|
Posted by Brian on 08/17/07 15:12
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 <id> field before it is
redisplayed. Looking for a sample code.
Thanks
<rss>
<item>
<id>3</id>
<name>Brian</name>
</item>
<item>
<id>1</id>
<name>James</name>
</item>
<item>
<id>5</id>
<name>Mark</name>
</item>
<item>
<id>2</id>
<name>Keith</name>
</item>
<item>
<id>4</id>
<name>Derek</name>
</item>
</rss>
<?php
$url = "test.xml";
$data = implode("", file($url));
preg_match_all ("/<item>([^`]*?)<\/item>/", $data, $matches);
// Begin feed
header ("Content-Type: text/xml; charset=ISO-8859-1");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
?>
<rss>
<?
foreach ($matches[0] as $match) {
preg_match ("/<id>([^`]*?)<\/id>/", $match, $temp);
$id = $temp['1'];
preg_match ("/<name>([^`]*?)<\/name>/", $match, $temp);
$description = $temp['1'];
// Echo RSS XML
echo "<item>\n";
echo "\t\t\t<id>" . $id . "</id>\n";
echo "\t\t\t<name>" . $name . "</name>\n";
echo "\t\t</item>\n";
}
?></rss>
Navigation:
[Reply to this message]
|