Need help sorting a XML file

Need help sorting a XML file

am 17.08.2007 17:12:02 von Brian

I have a similar xml file and I redisplay it with the following array in
PHP. What I would like to do is sort the field before it is
redisplayed. Looking for a sample code.

Thanks



3
Brian


1
James


5
Mark


2
Keith


4
Derek



$url = "test.xml";
$data = implode("", file($url));
preg_match_all ("/([^`]*?)<\/item>/", $data, $matches);

// Begin feed
header ("Content-Type: text/xml; charset=ISO-8859-1");
echo "\n";
?>




foreach ($matches[0] as $match) {

preg_match ("/([^`]*?)<\/id>/", $match, $temp);
$id = $temp['1'];

preg_match ("/([^`]*?)<\/name>/", $match, $temp);
$description = $temp['1'];

// Echo RSS XML
echo "\n";
echo "\t\t\t" . $id . "\n";
echo "\t\t\t" . $name . "\n";
echo "\t\t
\n";
}

?>

Re: Need help sorting a XML file

am 17.08.2007 17:24:49 von BJMurphy

On Aug 17, 11:12 am, "Brian" wrote:
> I have a similar xml file and I redisplay it with the following array in
> PHP. What I would like to do is sort the field before it is
> redisplayed. Looking for a sample code.
>
> Thanks
>
>
>
> 3
> Brian
>

>
> 1
> James
>

>
> 5
> Mark
>

>
> 2
> Keith
>

>
> 4
> Derek
>

>

>
> > $url = "test.xml";
> $data = implode("", file($url));
> preg_match_all ("/([^`]*?)<\/item>/", $data, $matches);
>
> // Begin feed
> header ("Content-Type: text/xml; charset=ISO-8859-1");
> echo "\n";
> ?>
>
>
>
> >
> foreach ($matches[0] as $match) {
>
> preg_match ("/([^`]*?)<\/id>/", $match, $temp);
> $id = $temp['1'];
>
> preg_match ("/([^`]*?)<\/name>/", $match, $temp);
> $description = $temp['1'];
>
> // Echo RSS XML
> echo "\n";
> echo "\t\t\t" . $id . "\n";
> echo "\t\t\t" . $name . "\n";
> echo "\t\t
\n";
>
> }
>
> ?>


Well, I think you mean to use $description in that second to last echo
statement, but that's not your question. If your ID's are unique, why
not build an array that maps the ID to the data (in this case just a
single string) and then you can sort and display as you please?