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 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题