欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > php >内容正文

php

php按照文件名字排序,php readdir 排序问题,如何按照日期进行排序

发布时间:2023/12/20 php 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 php按照文件名字排序,php readdir 排序问题,如何按照日期进行排序 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

目前是这么写的:

function posts_get($directory,$ext)

{

if (is_dir($directory)) {

$handle = opendir($directory);

while ($file = readdir($handle)){

$subdir = $directory . '/' .$file;

if ($file != '.' && $file !='..' && is_dir($subdir)){

posts_get($subdir,$ext);

} else if( $file != '.' && $file != '..') {

$fileInfo = pathinfo($subdir);

$fileExt = $fileInfo['extension'];

if ($fileExt == $ext){

echo '文件名:' . $file . '————' . '路径:' . '//' .$_SERVER['HTTP_HOST'] . '/' .$directory . '/' . $file . '
';

}}}

closedir($handle);

}

}

获取posts目录里面的html文件,测试目录里面有5个文件,404.html,405.html,406.html,407.html,408.html

输出的结果内容如下:

文件名:405.html————路径://hotbox.ryongyon.com/posts/405.html

文件名:406.html————路径://hotbox.ryongyon.com/posts/406.html

文件名:407.html————路径://hotbox.ryongyon.com/posts/407.html

文件名:408.html————路径://hotbox.ryongyon.com/posts/408.html

文件名:404.html————路径://hotbox.ryongyon.com/posts/404.html

请问如何将readdir的结果按照文件创建的日期进行排序

总结

以上是生活随笔为你收集整理的php按照文件名字排序,php readdir 排序问题,如何按照日期进行排序的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。