Codice PHP:
<?php
function loadXML2($domain, $path, $timeout = 100) {
$fp = fsockopen($domain, 80, $errno, $errstr, $timeout);
if($fp) {
// make request
$out = "GET $path HTTP/1.1\r\n";
$out .= "Host: $domain\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
// get response
$resp = "";
while (!feof($fp)) {
$resp .= fgets($fp, 128);
}
fclose($fp);
// check status is 200
$status_regex = "/HTTP\/1\.\d\s(\d+)/";
if(preg_match($status_regex, $resp, $matches) && $matches[1] == 200) {
// load xml as object
$parts = explode("\r\n\r\n", $resp);
return simplexml_load_string($parts[1]);
}
}
return false;
}
$new_icons=array("weather_thunderstorms-40.gif",
"weather_partlycloudy-40.gif",
"weather_sunny-40.gif",
"weather_overcast-40.gif",
"weather_rainsnow-40.gif",
"weather_mostlycloudy-40.gif",
"weather_rain-40.gif",
"weather_scatteredthunderstorms-40.gif",
"weather_scatteredshowers-40.gif",
"weather_snowflurries-40.gif",
"weather_haze-40.gif",
"weather_smoke-40.gif",
"weather_fog-40.gif",
"weather_dust-40.gif",
"weather_icy-40.gif",
"weather_snow-40.gif",
"weather_sleet-40.gif",
"weather_cloudy-40.gif",
"weather_drizzle-40.gif",
"weather_windy-40.gif",
"weather_heavyrain-40.gif",
"weather_heavysnow-40.gif",
"weather_scatteredsnowshowers-40.gif");
$old_icons=array("/ig/images/weather/thunderstorm.gif",
"/ig/images/weather/partly_cloudy.gif",
"/ig/images/weather/sunny.gif",
"/ig/images/weather/mostly_sunny.gif",
"/ig/images/weather/rain_snow.gif",
"/ig/images/weather/mostly_cloudy.gif",
"/ig/images/weather/rain.gif",
"/ig/images/weather/chance_of_storm.gif",
"/ig/images/weather/chance_of_rain.gif",
"/ig/images/weather/flurries.gif",
"/ig/images/weather/hazy.gif",
"/ig/images/weather/smoke.gif",
"/ig/images/weather/fog.gif",
"/ig/images/weather/dusty.gif",
"/ig/images/weather/icy.gif",
"/ig/images/weather/snow.gif",
"/ig/images/weather/sleet.gif",
"/ig/images/weather/cloudy.gif",
"/ig/images/weather/mist.gif",
"/ig/images/weather/storm.gif",
"/ig/images/weather/showers.gif",
"/ig/images/weather/rain_snow.gif",
"/ig/images/weather/chance_of_snow.gif");
$xml = loadXML2("google.com", "http://www.google.com/ig/api?weather=CITTA");
if($xml) {
$xml = simplexml_load_file("http://www.google.com/ig/api?weather=CITTA");
$information = $xml->xpath("/xml_api_reply/weather/current_conditions/condition");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$eh=$return_array['current_conditions']['icon'] = $xml->weather->current_conditions->icon['data'];
$meteo = str_replace($old_icons,$new_icons,$eh);
?>
[img]http://g0.gstatic.com/images/icons/onebox/<?php echo $meteo;?>[/img] CITTA, <?php echo $current[0]->temp_c['data'];?> °C
<?php } else {
}?>
Qualcuno di voi utilizza pure questa API? Utilizzate una funzione diversa?