I'm not sure whether this is a question about php or xml or what to be honest - a poke in the right direction would be much appreciated...
I'm storing news articles in XML format.
newsitems.php which contains the XML looks like this;
<?php
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<items>
<item id="1">
<date>10/12/05</date>
<topic>Topic</topic>
<head>Old News</head>
<info>
This is the oldest news item
</info>
<by>Me</by>
</item>
<item id="2">
<date>13/12/05</date>
<topic>Topic</topic>
<head>New News</head>
<info>
This is the most recent bit of news
</info>
<by>Me</by>
</item>
<items>
XML;
?>
and outputting the using the code below;
<?php
include 'newsitems.php';
$news = '<div class="main">' .
'<h1>Latest News</h1>';
$xml = simplexml_load_string($xmlstr);
foreach ($xml->item as $item) {
$news .=
'<div class="newsitem">
<table class="news" border="0">
<tr>
<td class="head"> '. $item->head .' </td>
<td class="topic"> '. $item->topic .' </td>
</tr>
<td class="info" colspan="2"> '. $item->info .' </td>
</tr>
<tr>
<td class="by" colspan="2">By: '. $item->by .' '. $item->date .' </td>
</tr>
</table>
</div>';
}
$news .= '</div>';
echo $news;
?>
The problem is that the articles run in the wrong order, oldest appearing at the top. How do I go about sorting the order they appear in based on the id attibute of <item> ? A link to the relevant bit of a manual or tutorial would be much appreciated - I don't even know where to start!