Extracting from RSS

Discussion in 'Web Design and Development' started by mikes63737, Nov 7, 2007.

  1. mikes63737 macrumors 65816

    Joined:
    Jul 26, 2005
    #1
    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
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    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');
     
  3. mikes63737 thread starter macrumors 65816

    Joined:
    Jul 26, 2005

Share This Page