每12幅图像的PHP div [英] PHP div for every 12 images
本文介绍了每12幅图像的PHP div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段代码:
<?
include( "http://api.flickr.com/services/feeds/photos_public.gne?id=22352410@N07&lang=en-us&format=php" );
$i = 0;
foreach($feed['items'] as $item) {
preg_match("/<img src=\"([^\"]+)\" .*? \/>/", $item['description'], $matches);
$img_html = $matches[0];
$img_src = $matches[1];
$medium_url = ereg_replace("_m", "_s", $img_src);
echo "$img_html";
}
?>
如何使每N张图片出现在<div></div>
内
示例:
How I could make that each N number of pictures appear inside of a <div></div>
Example:
<div class="container">
<img src="1.jpg" />
<img src="2.jpg" />
<img src="3.jpg" />
<img src="4.jpg" />
<img src="5.jpg" />
<img src="6.jpg" />
<img src="7.jpg" />
<img src="8.jpg" />
<img src="9.jpg" />
<img src="10.jpg" />
<img src="11.jpg" />
<img src="12.jpg" />
</div>
<div class="container">
<img src="13.jpg" />
<img src="14.jpg" />
<img src="15.jpg" />
<img src="16.jpg" />
<img src="17.jpg" />
<img src="18.jpg" />
<img src="19.jpg" />
<img src="20.jpg" />
<img src="21.jpg" />
<img src="22.jpg" />
<img src="23.jpg" />
<img src="24.jpg" />
</div>
等...
任何想法?
非常感谢!
推荐答案
关于double div:将if语句移至该语句下方,该语句检查是否存在剩余数,该语句位于递增计数器的语句下方,并且不会创建该计数器.双重div:
About the double div: Move the if statement, that checks whether there is a remainder down, below the statement that increments the counter, and it will not create the double div:
<?
include( "http://api.flickr.com/services/feeds/photos_public.gne?id=22352410@N07&lang=en-us&format=php" );
$i = 0;
echo "<div class='container'>";
foreach($feed['items'] as $item)
{
preg_match("/<img src=\"([^\"]+)\" .*? \/>/", $item['description'], $matches);
$img_html = $matches[0];
$img_src = $matches[1];
$medium_url = ereg_replace("_m", "_s", $img_src);
echo "$img_html";
$i++;
if($i % 12 === 0)
print "</div><div class='container'>";
}
print "</div>";
?>
这篇关于每12幅图像的PHP div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文