<?php

/***************************************************************************************/
/*	YAHOO */
/***************************************************************************************/
//Point to XML File
$feed = "http://weather.yahooapis.com/forecastrss?p=USRI0061&u=f";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $feed);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$feed = curl_exec($ch);

//Create Object of SimpleXMLElement Class
$sxml = simplexml_load_string($feed);
//Register Namespaces
$sxml->registerXPathNamespace('yweather', 'http://xml.weather.yahoo.com/ns/rss/1.0');
$sxml->registerXPathNamespace('geo', 'http://www.w3.org/2003/01/geo/wgs84_pos#');

/*Extract RSS version number
foreach ($sxml->attributes() as $key=>$value){
        echo "RSS $key $value";
}
//Echo Channel node names & values
foreach($sxml->channel->children() as $name => $value) {
        echo $name . ": " . $value .'<br/>';
}
*/

                        
$yweatherArray = array();
/*** LOCATION : CITY, REGION, COUNTRY  **/
$yweatherArray = $sxml->channel->xpath('yweather:location');
if ($yweatherArray[0]){
        foreach ($yweatherArray[0]->attributes() as $name => $value){
                $$name = $value;
        }
}
/*** UNITS : TEMPERATURE, DISTANCE, PRESSURE, SPEED  **/
$yweatherArray = $sxml->channel->xpath('yweather:units');
if ($yweatherArray[0]){
        foreach ($yweatherArray[0]->attributes() as $name => $value){
                $$name = $value;
        }
}
/*** WIND : CHILL, DIRECTION, SPEED  **/
$yweatherArray = $sxml->channel->xpath('yweather:wind');
if ($yweatherArray[0]){
        foreach ($yweatherArray[0]->attributes() as $name => $value){
                $$name = $value;
        }
}
/*** ATMOSPHERE : HUMIDITY, VISIBILITY, PRESSURE, RISING  **/
$yweatherArray = $sxml->channel->xpath('yweather:atmosphere');
if ($yweatherArray[0]){
        foreach ($yweatherArray[0]->attributes() as $name => $value){
                $$name = $value;
        }
}
/*** ASTRONOMY : SUNRISE & SUNSET **/
$yweatherArray = $sxml->channel->xpath('yweather:astronomy');
if ($yweatherArray[0]){
        foreach ($yweatherArray[0]->attributes() as $name => $value){
                $$name = $value;
        }
}
/*** CONDITION : TEXT, CODE, TEMP, DATE  **/
$yweatherArray = $sxml->channel->xpath('yweather:condition');
if ($yweatherArray[0]){
        foreach ($yweatherArray[0]->attributes() as $name => $value){
                $$name = $value;
        }
}
/*** FORECAST : DAY, DATE, LOW, HIGH, TEXT, CODE  **/
$yweatherArray = $sxml->channel->xpath('yweather:forecast');
if ($yweatherArray[0]){
        foreach ($yweatherArray[0]->attributes() as $name => $value){
                $$name = $value;
        }
        foreach ($yweatherArray[1]->attributes() as $name => $value){
                $$name = $value;
        }
}

//iterate through array items
foreach ($sxml->channel->item as $item){
        $strtemp = "$item->description<br /><br />\n";
        echo $strtemp;
}
/*
echo $sunrise;
echo
'       Current Conditions: <br />' .
        $text . ', ' . $temp .' '. $temperature . '<br />'
        . 'High: ' . $high . '<br />'
        . 'Low: ' . $low . '<br />
'
*/
?>