Jump to content

ginkworm

New Members
  • Posts

    1
  • Joined

  • Last visited

ginkworm's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have these files in a directory and can easily list to a webpage Daily_CD_20130902.xml Daily_CD_20130903.xml Daily_CO_20130902.xml Daily_CO_20130903.xml Daily_CU_20130902.xml Daily_CU_20130903.xml Daily_EQ_20130902.xml Daily_EQ_20130903.xml Daily_IR_20130902.xml Daily_IR_20130903.xml However, i want to be selective and just select the most recent of each type, so instead of the whole list i want to display Daily_CD_20130903.xml Daily_CO_20130903.xml Daily_CU_20130903.xml Daily_EQ_20130903.xml Daily_IR_20130903.xml Is there an easy way to do this or do i need to take apart the filename, put the date in a date object and then use it to sort. my current code is: public function getFiles() { //return String, form as HTML later $return = ""; // create a resrouce pointing to the directory with the files in it on disk $dir = opendir('DIRECTORY'); //path to that directory that is appended to the URL $actualdir = 'PATH FROM WEBSERVER ROOT'; // read the directory looping over the files and populate to an array while ($entryName = readdir($dir)){ $dirArray[] = $entryName; } //close the directory as we don't need it anymore closedir($dir); //make a note of how many items are in the directory $indexCount = count($dirArray); //loop through the files building up a list of links for($index=0; $index < $indexCount; $index++) { if($dirArray[$index] !="." && $dirArray[$index] !=".."){ $return .= "<a href='"."$actualdir".$dirArray[$index]."'>".$dirArray[$index]."</a><br/>"; } } return $return; } any help is appreciated as this is my first day of PHP
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.