In questo tutorial vedremo come ottenere le previsioni meteo utilizzando PHP e le API di Google.

 
< ?php
function getWeatherForecast() {
 
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, ‘http://www.google.com/ig/api?weather=bn424nt&hl=en’);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$xml_str = curl_exec($ch);
curl_close($ch);
 
$xml = new SimplexmlElement($xml_str);
$count = 0;
echo
;
     foreach($xml->weather as $item) {
          foreach($item->current_conditions as $new) {
                                echo
.
Now
 
.
;
                                                echo .
 
;
                                                                echo
.round((($new->temp_f[‘data’]* 1)-32) * (5 * 1) / (9 *1),1). ‘°C
 
;    
                                                                echo
. $new->wind_condition[‘data’] .
 
;
                                                echo
 
Summary:
. $new->condition[‘data’] .
 
;
                                echo
 
;
 
               }        
          foreach($item->forecast_conditions as $new) {
                                echo
;
                                                echo
. $new->day_of_week[‘data’] .
 
;
                                                echo

 
;
                                                                echo
Low ‘
.round((($new->low[‘data’]* 1)-32) * (5 * 1) / (9 *1),1). ‘°C
 
;            
                                                                echo
High ‘
.round((($new->high[‘data’]* 1)-32) * (5 * 1) / (9 *1),1). ‘°C
 
;          
                                                echo

Summary: ‘ . $new->condition[‘data’] .
 
;
                                echo
 
;
          }
 
}
echo ;
}
getWeatherForecast();
?>      
 

fonte: www.sastgroup.com ? Vai al post originale