我正在使用一個簡單的代碼,其中包括一個雅虎API代碼,只是從我的城市得到的天氣,並放在我的網頁上,但是,我只是讀雅虎公共API不再工作我不知道如何才能得到這個代碼工作,我有一個雅虎帳戶,我創建了一個API,我不知道如何從這裏開始。如果有人能幫助我,這是代碼:簡單的雅虎天氣Api不工作
<?php
/*Clima*/
if(isset($_POST['zipcode']) && is_numeric($_POST['zipcode'])){
$zipcode = $_POST['zipcode'];
}else{
$zipcode = 'ARMA0056';
}
$result = file_get_contents('http://weather.yahooapis.com/forecastrss?p=' . $zipcode . '&u=c');
$xml = simplexml_load_string($result);
//echo htmlspecialchars($result, ENT_QUOTES, 'UTF-8');
$xml->registerXPathNamespace('yweather', 'http://xml.weather.yahoo.com/ns/rss/1.0');
$location = $xml->channel->xpath('yweather:location');
if(!empty($location)){
foreach($xml->channel->item as $item){
$current = $item->xpath('yweather:condition');
$forecast = $item->xpath('yweather:forecast');
$current = $current[0];
$clima = <<<END
<span>{$current['temp']}°C</span>
END;
}
}else{
$clima = '<h1>No results found, please try a different zip code.</h1>';
}
/*Clima*/
?>
有時,'results'是'null',還與雅虎例子.. –