I have been trying to parse the yahoo weather feed for inclusion on my site using PHP and SimpleXML. I am returning the feed correctly however when I put the feed through “simplexml_load_string” some of the attributes are not being parsed into my simpleXML object. These attributes are the main elements with weather info y:weather that are not appearing in my object.
I have scoured google, yahoo developer help and there tutorials and can see nothing about why my object may be broken.
Code so far is :
<?php
$request = 'http://weather.yahooapis.com/forecastrss?p=34747';
//echo $request;
//make request using curl
$session = curl_init($request);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
//get url and attach as img
$phpobject = simplexml_load_string($response);
$weather = $phpobject->channel[0];
print '<p><img src="'.$weather->image->url.'" width="'.$weather->image->width.'" height="'.$weather->image->height.'" /></p>';
print '<p><strong>'.$weather->description.'</strong></p>';
?>