Re: Sorting a file

From: Date: Fri, 28 Feb 2003 17:13:10 +0000
Subject: Re: Sorting a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-137589@lists.php.net to get a copy of this message
Yep, that did it. Thanks. ----- Original Message ----- From: "Ernest E Vogelsinger" <ernest@vogelsinger.at> To: "Beauford.2002" <beauford.2002@rogers.com> Cc: "PHP General" <php-general@lists.php.net> 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=1>Bonk > ><Option VALUE=3>Alfredsson > ><Option VALUE=4>Neil > ><Option VALUE=5>Chara > ><Option VALUE=7>Lalime > ><Option VALUE=15>Hossa > ><Option VALUE=18>Phillips > ><Option VALUE=20>Redden > ><Option VALUE=21>Havlat > --------------------[snip]-------------------- > > Try something like this (untested): > $array = file($infile); > > // exchange the <option> and name parts > // <option value="something">Name > // will become > // Name<option 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 > >

« previous php.general (#137589) next »