首页 > 解决方案 > 如何在根文件夹的顶部对最新的文本文件内容进行排序和显示

问题描述

无法有效地对一批文本文件和内容进行排序并显示最新到旧。

我试过 natsort ($directory);

<?php
$directory = "feeds/";
$dir = opendir($directory);
while (($file = readdir($dir)) !== false) {
    $filename = $directory . $file;
    $type = filetype($filename);
    if ($type == 'file') {
        $contents = file_get_contents($filename);
        $items = explode('\n', $contents);
        echo '<table width="100%" border="1" 
        cellpadding="4" bgcolor="#fff" id="rcorners">';
        foreach ($items as $item) {
            echo"<tr><td id='rcorners'>".nl2br
            ($item)."</td></tr>\n";

        }
        echo '</table>';
    }
}
closedir($dir);
?>

没有错误只是不要从最新到最旧排序。

标签: php

解决方案


推荐阅读