dqxhit3376 2014-05-26 16:35
浏览 57
已采纳

简单的PHP,回显<li> ... </ li>目录中的所有图像

I'm attempting to make a simple responsive gallery using bootstrap 3 and a simple php script to display all images in a specific directory I in response to another question on here.

The issue I'm having is echoing the the required <li></li> tags rather then <br></br> as demonstrated below.


here is how I currently display the images, within the <li></li>tag with a class to display the images layout/positioning, called in the <ul></ul> tag.

<div class="container">
          <ul class="row">
            <li class="col-lg-2 col-md-2 col-sm-3 col-xs-4">
                <img class="img-responsive" src="images/kitchens.jpg">
            </li>
            <li class="col-lg-2 col-md-2 col-sm-3 col-xs-4">
                <img class="img-responsive" src="images/garden.jpg">
            </li>
            <li class="col-lg-2 col-md-2 col-sm-3 col-xs-4">
                <img class="img-responsive" src="images/front.jpg">
            </li>
          </ul>
</div> <!-- /container --> 

this is the PHP im using in response to question i found here https://stackoverflow.com/a/19255786/3599850

<?php
$files = glob("images/*.*");

for ($i=0; $i<count($files); $i++) {
    $image = $files[$i];
    print $image ."<br />";
    echo             

    '<img src="'.$image .'" alt="Random image" />'."<br /><br />";
}

?>

This is my attempt :(

<?php
$files = glob("images/*.*");

for ($i=0; $i<count($files); $i++) {
    $image = $files[$i];
    print $image ."<br />";
    echo

    '<li class="col-lg-2 col-md-2 col-sm-3 col-xs-4">
    <img src="'.$image .'" alt="Random image" /></li>'."<li /><li />";
}

?>
  • 写回答

1条回答 默认 最新

  • dsuxcxqep31023992 2014-05-26 16:40
    关注

    You have too many closing </li> tags :

    <?php
    $files = glob("images/*.*");
    
    for ($i=0; $i<count($files); $i++) {
        $image = $files[$i];
        echo '<li class="col-lg-2 col-md-2 col-sm-3 col-xs-4"><img  class="img-responsive" src="'.$image .'" /></li>';
    }
    
    ?>
    

    And you don't need the print $image ."<br />";

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程