du_1993 2015-10-31 10:25
浏览 55
已采纳

如何在上次修改日期glob PHP上订购文件名

I've got this code:

<?php 
  foreach (glob("*files/*.html") as $filename) { 
  echo "<iframe src=$filename></iframe>"; 
} 
?>

The structure is like this:

|-index.php
|-files 
   |- are.html
   |- hello.html
   |- who.html
   |- you.html

The problem is: it isn't sorted on date. I tried it with filemtime (http://php.net/manual/en/function.filemtime.php) with this code:

<?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));
}
?> 

but it only echoes 1 of the 4 html's I got in that directory: you.html How can I let it echo all 4 html's on last modified date?

  • 写回答

1条回答 默认 最新

  • duanjia8215 2015-11-08 16:27
    关注

    This works :)

    $myFiles = glob("*files/*.html");
    usort($myFiles, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
    
    foreach ($myFiles as $filename) { 
    echo "<iframe src=$filename></iframe>"; 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式