[英]Display images in html table (IF loop)
我正在尋找編寫一個PHP腳本,該腳本會將來自目錄的圖像發布為8列寬的表格格式,並且行擴展的圖像數與原來一樣。 當前代碼中我僅將它們發布在單獨的行中。 如何將它們分成8張圖像的行?
<?php
$files = glob("images/*.*");
for ($i=1; $i<count($files); $i++)
{
$image = $files[$i];
$supported_file = array(
'gif',
'jpg',
'jpeg',
'png'
);
$ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
if (in_array($ext, $supported_file)) {
// print $image ."<br />";
echo '<a href="' .$image .'"><img src="'.$image .'" alt="Random image" width=200 /></a>'."<br /><br />";
} else {
continue;
}
}
?>
像這樣嗎 $ i%8每8行返回0,所以我們要做的就是基本上停止/啟動<tr>
標記。
<table>
<tr>
<?php
$files = glob("images/*.*");
for ($i = 1; $i < count($files); $i++) {
$image = $files[$i];
$supported_file = array(
'gif',
'jpg',
'jpeg',
'png'
);
$ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
if (in_array($ext, $supported_file)) {
// print $image ."<br />";
echo '<td><a href="' . $image . '"><img src="' . $image . '" alt="Random image" width=200 /></a></td>';
}
if ($i % 8 === 0) {
echo "</tr><tr>";
}
}
?>
</tr>
</table>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.