Preserved Topic: Sorting flat text files (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: New Jersey, USA |
posted 12-27-2001 21:12
I have a flat text file delimited with pipes that looks like this: |
Maniac (V) Mad Scientist From: Belgrade, Serbia |
posted 12-27-2001 21:28
Read all lines from your text file into array, write function that compares two date items, use usort() function to sort array using your date comparing function... |
Paranoid (IV) Inmate From: New Jersey, USA |
posted 12-27-2001 21:43
Thanks for the start mr.maX! |
Paranoid (IV) Inmate From: New Jersey, USA |
posted 12-28-2001 03:31
Okay, after mr.maX pointed me in the right direction, and after spending some time in the online PHP manual (I love that thing), I have come up with this code. Whats even more amazing is... IT WORKS! I'm just not sure why. I know I've made $my_array a two dimentional array, which is why I'm having trouble understanding why this works. What makes the sort function sort on the date field which would be $my_array[0][0], and $my_array[1][1], ect. if my thinking is correct. |
Paranoid (IV) Inmate From: Minneapolis, MN, USA |
posted 12-28-2001 05:12
$my_array is an array of arrays (each of which contains one row's worth of values) |
Maniac (V) Mad Scientist From: Belgrade, Serbia |
posted 12-28-2001 09:37
Actually, I haven't suggested that you use sort() function, Butcher And there's one simple reason why - it won't sort dates correctly. It sorts array using simple alphanumeric comparing routine. If your text file contained entries for the next year, it wouldn't be sorted correctly. For example put the following in your text file and you'll see: |
Paranoid (IV) Inmate From: New Jersey, USA |
posted 12-28-2001 12:48
Thanks mr.maX |
Paranoid (IV) Inmate From: New Jersey, USA |
posted 12-28-2001 22:53
I'm sorry jiblet, |