0

我正在尝试让一个网页显示四个 div,这些 div 将包含一个 img 和一个描述。我想使用循环,因为我将有许多包含这些 div 的其他页面。这是我现在使用的代码:

for ($i=0;$i<4;$i++)
{
    echo '<div class="item">
    <img src="IMGs\\' . $items[$i]["ImgFilename"] . '" />
    <h6 class="panel">Description</h6>
    </div>';
}

我相信问题在于我没有以正确的方式逃避。我一直在寻找一段时间,但找不到合适的组合。文件存储在 IMGs\file.jpg 中,其中 file.jpg 是从数组中提取的。

4

3 回答 3

3

你的逃跑对我来说似乎很好。但是,我认为问题出在双反斜杠上。例如,删除并将其\\替换为/因此该行变为:

<img src="IMGs/' . $items[$i]["ImgFilename"] . '" />

于 2013-04-14T10:46:48.533 回答
1

你不需要逃避这个。改变这个:

<img src="IMGs\\' . $items[$i]["ImgFilename"] . '" />

<img src="IMGs/' . $items[$i]["ImgFilename"] . '" />

于 2013-04-14T10:46:40.223 回答
1

您可以根据需要通过闯入/退出 PHP 来更好地布置代码,这是一个简单的示例:-

<?php for($index = 0; $index < 4; $index++): ?>
    <div class="item">
        <img src="IMGs/<?php echo $items[$index]["ImgFilename"]; ?>" />
        <h6 class="panel">Description</h6>
    </div>
<?php endfor; ?>
于 2013-04-14T10:47:06.483 回答