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


$rss = simplexml_load_file('');

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" />

thanks in advance


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

$rss = simplexml_load_file('');

$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:

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