Simple RSS parse

Hey chaps, never done this before, so obviously i’ll appear dumb!

I want to add weather onto a page using yahoo weather. Im only looking at the ‘code’ (for my own image population later), ‘temp’, ‘text’

at the mo i have

<?php

$rss = simplexml_load_file('http://weather.yahooapis.com/forecastrss?w=2442047&u=c');

echo $rss->channel->item->title . '<br />';
?>

which is fine, brings in the title, however how to i echo/split this section to pull down the key data of ‘text’, ‘code’ and ‘temp’ separately

<yweather:condition  text="Mostly Cloudy"  code="28"  temp="50"  date="Fri, 18 Dec 2009 9:38 am PST" />
    <description><![CDATA[

thanks in advance

b

Here’s a quicky snippet to give you an idea of where to look.


$rss = simplexml_load_file('http://weather.yahooapis.com/forecastrss?w=2442047&u=c');

$condition = $rss->channel->item->children('yweather', true)->condition->attributes();

$text = (string) $condition->text;
$code = (int)    $condition->code;
$temp = (int)    $condition->temp;
$date = (string) $condition->date;

var_dump($text, $code, $temp, $date);

The condition element is under the yweather namespace so we must use children() to access it. Also, the example uses attributes() since we only want the attributes (blah="foo").

See also:
http://php.net/simplexmlelement.children
http://php.net/simplexmlelement.attributes

If you want/need fuller explanation, just ask! (: