我有这段代码:
<?php
foreach (glob("*files/*.html") as $filename) {
echo "<iframe src=$filename></iframe>";
}
?>
结构是这样的:
|-index.php
|-files
|- are.html
|- hello.html
|- who.html
|- you.html
问题是:它没有按日期排序。我用filemtime(http://php.net/manual/en/function.filemtime.php)尝试了这段代码:
<?php
foreach (glob("*files/*.html") as $filename) {
echo "<iframe src=$filename></iframe>";
}
if (file_exists($filename)) {
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>
但它只回应了我在该目录中获得的4个html中的1个:you.html 如何让它在最后修改日期回显所有4个html?
答案 0 :(得分:0)
这有效:)
$myFiles = glob("*files/*.html");
usort($myFiles, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
foreach ($myFiles as $filename) {
echo "<iframe src=$filename></iframe>";
}