Extracting from RSS

mikes63737

macrumors 65816
Original poster
Jul 26, 2005
1,133
310
I have an RSS feed (http://xml.weather.yahoo.com/forecastrss?p=USCT0139&u=f) and I want to extract a certain line from it using PHP and then get one thing from that line. The line is
Code:
<yweather:condition text="Fair" code="33" temp="40" date="Wed, 07 Nov 2007 8:53 pm EST"/>
and I only want the "40".

I've searched and I can't find how to do this. I might not be searching for the right thing.

Thanks!

Mike
 

angelwatt

Moderator emeritus
Aug 16, 2005
7,857
7
USA
Here you go. I tried it out and worked. The $temp variable stores the 40 degrees that you're trying to get.

PHP:
$doc = new DOMDocument();
$doc->load("http://xml.weather.yahoo.com/forecastrss?p=USCT0139&u=f");
$weather = $doc->getElementsByTagNameNS(
  'http://xml.weather.yahoo.com/ns/rss/1.0', 'condition')->item(0);

$temp = $weather->getAttribute('temp');
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.