开发者

How can I use PHP to include the most recent file in a directory?

I have a directory which will look something like this:

/test/
  |
  |- index.php
  |- test-20110324
  |- test-20090901
  |- test-20070901

What I want to do is use "index.php" to find the most up-to-date file, and require it into the "index.php" file.

Please note: The included file needs to be selected by the date-stamp suffix, as opposed to the file modification time, as these older files my need to be edited-in-place, without taking precedence over the most up-to-date file.

This concept will be applied over several directories, but the HTML files will all following the pattern above, i.e. WORD-YYYYMMDD.

Any ideas on how to do this? I will be very grateful if anybody could spare a moment to help me out here!!!

Th开发者_开发技巧anks in advance!


Shouldn't be too hard:

$files = glob('*.*'); // change the filemask as you like, prepend a path, etc.
sort($files);         // can be customized with usort if default sort isn't satisfactory
$newest = array_pop($files); // get the last element ("greatest" after sorting);
echo $newest;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜