Tuesday, March 6, 2012

get yahoo weather from yahoo weather xml uisng php and curl

0
if you want to get the yahoo weather from yahoo xml feeds then this code will help you

currently it will show you temperature of uae city but you can modified it by just adding respective city code

So enjoy...);

<?php 

set_time_limit(0);

function retrieveYahooWeather($code) {

$yahooUrl = "http://weather.yahooapis.com/forecastrss";

$yahooZip = "?p=$code&u=c";

$yahooFullUrl = $yahooUrl . $yahooZip; 

$curlObject = curl_init();

curl_setopt($curlObject,CURLOPT_URL,$yahooFullUrl);

curl_setopt($curlObject,CURLOPT_HEADER,false);

curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true);

$returnYahooWeather = curl_exec($curlObject);

curl_close($curlObject);

return $returnYahooWeather;

}

$code=array('AEXX0001','AEXX0002','AEXX0003','AEXX0004'
,'AEXX0005','AEXX0006','AEXX0007','AEXX0008');

foreach($code as $newcode){

retrieveYahooWeather($newcode);

$localZipCode = "$newcode"; // Lake Arrowhead, CA

$weatherXmlString = retrieveYahooWeather($localZipCode);

$weatherXmlObject = new SimpleXMLElement($weatherXmlString);

$currentCondition = $weatherXmlObject->xpath("//yweather:condition");

$currentTemperature = $currentCondition[0]["temp"];

$currentDescription = $currentCondition[0]["text"];

?>



<?
}


No comments :

Post a Comment