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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?