Quantcast
Viewing latest article 17
Browse Latest Browse All 24

Answer by Duncan for XML RSS Feed Parse PHP

I'd personally use SimpleXML for this, you just have to bear in mind the custom namespace which is being used to carry the weather data, here's a little example (with no error handling etc) which I've just tested and fetches the current weather.

//Fetch the feed$feed = file_get_contents("http://rss.weather.com.au/sa/adelaide");//Load it into simplexml$weather = simplexml_load_string($feed);//Get namespace descendants using the w namespace defined in the feed$channelelements = $weather->channel->item->children("http://rss.weather.com.au/w.dtd");//Looping through each of the attributes and echoing them, you can do what you want with them at this pointforeach($channelelements->attributes() as $k => $attr) {    echo $k.' = '.$attr.'<br />';}

Viewing latest article 17
Browse Latest Browse All 24

Trending Articles