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