07-07-2010, 03:04 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Nov 2007
Posts: 41
Thanks: 24
|
sorting simplexml data by date
Need help with sorting simplexml data by date.
I'm pulling data from an xml feed with simplexml. But the problem is the output doesn't have any kind of ordering. I want to be able to sort them by date. (sort order being from now to future) How would I go about that?
Date value is in this format: 2011-06-17 from $r25->start_date
Here's how my code looks
PHP Code:
$urL = "http://www.domain.com/feed.xml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urL);
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$feed = $output;
$xml = new SimpleXmlElement($feed);
$msg = "";
foreach($xml->children('http://www.testnet.com/r25') as $entry){
$namespaces = $entry->getNameSpaces(true);
$r25 = $entry->children($namespaces['r25']);
$evDate = date('F n, Y (l)',strtotime($r25->start_date));
$msg .= "<li><span class=\"date\">$evDate</span> - <span class=\"eventTitle\">$r25->event_name</span></li>\n\n";
}
__________________
"Things you can get access to, you should never memorize." -Albert Einstein
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
|
|
|
|