Simple Yahoo Weather Api Not Working

Cruzaderplyr picture Cruzaderplyr · Mar 27, 2016 · Viewed 32.8k times · Source

I was using a simple code which includes a yahoo api code to get just the weather from my city and put in on my web page, however, i just read that yahoo public api is no longer working and i dont know how can a i get this code to work, i have a yahoo account, i created an api and i dont know how to proceed since here. If somebody can help me this is the code:

<?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']}&deg;C</span>

END;
    }
}else{
    $clima = '<h1>No results found, please try a different zip code.</h1>';
}
/*Clima*/
?> 

Answer

blackxel picture blackxel · Mar 28, 2016

just replace http://weather.yahooapis.com with http://xml.weather.yahoo.com. credits to https://forum.rainmeter.net/viewtopic.php?f=13&t=23010