1

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!!!

Thanks in advance!

Jordan Clark
  • 750
  • 5
  • 18

1 Answers1

3

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;
Jon
  • 428,835
  • 81
  • 738
  • 806
  • Thanks for your help, Jon! The only thing was, I needed it to **display** the file, rather than just echo the file name. However, simply changing the last line to `include($newest);` done the trick! Thanks a lot Jon, that advice was invaluable to a PHP novice like me! – Jordan Clark Mar 24 '11 at 21:51