dongyuchen0214 2010-09-06 18:51
浏览 59
已采纳

每12张图片的PHP div

i have this piece of code:

<?
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";
    }

?>

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>

etc...

Any Ideas??

Thanks so much!!!

  • 写回答

6条回答 默认 最新

  • duanhe1903 2014-07-20 11:21
    关注

    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>";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加