Sorting values in a text file by date?

Associate
Joined
29 Dec 2004
Posts
2,253
Hi there,

I have a text file which contains values like this:

flatfile.txt said:
15/10/2008 WS - Mr Tester. Some test details
04/11/2008 BH - Dr Feelgood. Some test details
12/11/2008 BH - Ms Test. Some test details
22/10/2008 BH - Mrs Jones. Some test details
30/09/2008 WS - Mr Smith. Some test details
01/10/2008 WS - Mr Pesky. Some test details
15/10/2008 WS - Mr Fitz. Some test details

I use PHP to display the list, but at the moment it is displayed as each line is read (basically it's displayed as shown above)...is there a way to sort it by the date so it is displayed with the nearest events first? Here is the bit of code i use to simply display the list as it is at the moment:

PHP:
<?php
$file_handle = fopen("../path/to/flatfile.txt", "rb");

while (!feof($file_handle) ) {
        $line_of_text = fgets($file_handle);
        echo '$line_of_text';
}

fclose($file_handle);
?>

Can anyone help?
 
I got that from general Googling, but unfortunately none of the code i found helped me to do what i want - could you give some examples of code that i could adapt?
 
Wow thanks for all that, really appreciate it - i seem to be getting this error though:

Warning: mktime() expects parameter 4 to be long, string given in /path/files.php on line 70

Warning: mktime() expects parameter 5 to be long, string given in /path/file.php on line 70

The exact contents of my text file is this as i expect this is the issue...i had to take the stars out before as the forum was processing them as bullet points, oh and unfortunately i have to have the "Projects" header at the top as the calendar application that is also using this data uses it to define things:

Code:
====== Projects =====

  * 15/10/2008 WS - Mr Tester. Some test details
  * 04/11/2008 BH - Dr Feelgood. Some test details
  * 12/11/2008 BH - Ms Test. Some test details
  * 22/10/2008 BH - Mrs Jones. Some test details
  * 30/09/2008 WS - Mr Smith. Some test details
  * 01/10/2008 WS - Mr Pesky. Some test details
  * 15/10/2008 WS - Mr Fitz. Some test details
 
I thought the substr part was the issue as i could see it was reffering to specific points of the text file to get the date...i did also look on PHP.net at the function but just couldn't get it exactly right, i then had to give up before my mind started to melt :p

All is working a treat now, i just need to put in some if statements to make sure it only prints results for this month or next month...but i enjoy the challenges i can do!

Many thanks for your help, you sir are a gentleman.
 
Back
Top Bottom