[PHP] Sorting a file
I have the file below which I need to sort by player and then rewrite it, this file will then be used as part of another part of my input process on my site. A couple of things. I am able to read the file into an array using 'file', I think, but I am not able to sort it. I have tried different variatons of 'sort' and it doesn't do it properly. One other question though, when I display the contents of the array in my browser, I only get the players name and not the Option VALUE=?, I am assuming this is because of the way IE has interpreted it and that the entire line did actually get read, but who knows. Any help is appreciated. Option VALUE=1Bonk Option VALUE=3Alfredsson Option VALUE=4Neil Option VALUE=5Chara Option VALUE=7Lalime Option VALUE=15Hossa Option VALUE=18Phillips Option VALUE=20Redden Option VALUE=21Havlat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sorting a file
At 16:41 28.02.2003, Beauford.2002 spoke out and said: [snip] I have the file below which I need to sort by player and then rewrite it, this file will then be used as part of another part of my input process on my site. A couple of things. I am able to read the file into an array using 'file', I think, but I am not able to sort it. I have tried different variatons of 'sort' and it doesn't do it properly. One other question though, when I display the contents of the array in my browser, I only get the players name and not the Option VALUE=?, I am assuming this is because of the way IE has interpreted it and that the entire line did actually get read, but who knows. Option VALUE=1Bonk Option VALUE=3Alfredsson Option VALUE=4Neil Option VALUE=5Chara Option VALUE=7Lalime Option VALUE=15Hossa Option VALUE=18Phillips Option VALUE=20Redden Option VALUE=21Havlat [snip] Try something like this (untested): $array = file($infile); // exchange the option and name parts // option value=somethingName // will become // Nameoption value=something $array = preg_replace('/(.*?)(.*)/', '$2$1', $array); // now sort the array $array = sort($array); // exchange the parts back $array = preg_replace('/(.*?)(.*)/', '$2$1', $array); // and finally save it to a file though, when I display the contents of the array in my browser, I only get the players name and not the Option VALUE=?, I am assuming this is because of the way IE has interpreted it and that the entire line did actually get read, but who knows. Try echoing using htmlentities(), IE (and all other browsers) will need to eat the option parts - it's a valid html tag (even outside a form) -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Sorting a file
Yep, that did it. Thanks. - Original Message - From: Ernest E Vogelsinger [EMAIL PROTECTED] To: Beauford.2002 [EMAIL PROTECTED] Cc: PHP General [EMAIL PROTECTED] Sent: Friday, February 28, 2003 10:50 AM Subject: Re: [PHP] Sorting a file At 16:41 28.02.2003, Beauford.2002 spoke out and said: [snip] I have the file below which I need to sort by player and then rewrite it, this file will then be used as part of another part of my input process on my site. A couple of things. I am able to read the file into an array using 'file', I think, but I am not able to sort it. I have tried different variatons of 'sort' and it doesn't do it properly. One other question though, when I display the contents of the array in my browser, I only get the players name and not the Option VALUE=?, I am assuming this is because of the way IE has interpreted it and that the entire line did actually get read, but who knows. Option VALUE=1Bonk Option VALUE=3Alfredsson Option VALUE=4Neil Option VALUE=5Chara Option VALUE=7Lalime Option VALUE=15Hossa Option VALUE=18Phillips Option VALUE=20Redden Option VALUE=21Havlat [snip] Try something like this (untested): $array = file($infile); // exchange the option and name parts // option value=somethingName // will become // Nameoption value=something $array = preg_replace('/(.*?)(.*)/', '$2$1', $array); // now sort the array $array = sort($array); // exchange the parts back $array = preg_replace('/(.*?)(.*)/', '$2$1', $array); // and finally save it to a file though, when I display the contents of the array in my browser, I only get the players name and not the Option VALUE=?, I am assuming this is because of the way IE has interpreted it and that the entire line did actually get read, but who knows. Try echoing using htmlentities(), IE (and all other browsers) will need to eat the option parts - it's a valid html tag (even outside a form) -- O Ernest E. Vogelsinger (\) ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php