PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi,
I'm new to PHP, but have used Javascript quite a bit before. I wanted to create a script that retrieves filenames from a folder on my webserver, then reverse sorts those files and makes them into clickable links. After some searching on Google, I decided PHP was the way to go, and so I wrote the following script. The filenames are in the format "Entos_Web_MM-DD-YY.pdf", and I use the substr command to shorten the text of the links to just "MM-DD-YY". The problem I'm having is that this only sorts based on month first, then day, then year (as would be expected since that is the order the characters are in). However, I'd like it to sort it on year first, so that the ones from January 2011 come before December 2010 files. I'm sure there's a way to do this by using the substr command to get only the "YY" portion of the filename and sort based on that, but I'm struggling with how exactly to do that and put it back into the array.
VladSun wrote:take a look at the glob() function in PHP
I'm not sure I understand how that will help. I can see how it might give me an array of all files that have a specified value, such as "11" for the year, but that doesn't seem very clean since it requires the hard-coding of the year. Am I missing something? Perhaps an example would help.