Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikes63737

macrumors 65816
Original poster
Jul 26, 2005
1,157
341
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
 
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');
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.