Prova così:
Codice PHP:
<?php
class Previsioni {
private $day_of_week=Array();
public function show($citta) {
$xml = new SimpleXMLElement($this->load_file("http://www.google.com/ig/api?weather=$citta,italy&hl=en"));
$information = $xml->xpath("/xml_api_reply/weather/forecast_information");
$current = $xml->xpath("/xml_api_reply/weather/current_conditions");
$forecast_list = $xml->xpath("/xml_api_reply/weather/forecast_conditions");
//echo "<div id=\"bg\">\n";
$Adesso = "<div id=\"cont_tempo\">";
$Adesso.= "<img id=\"img_tempo\" border=\"0\" src=\"http://www.google.com".$current[0]->icon['data']."\" alt=\"". $current[0]->condition['data']."\" />\n";
$Adesso.= "<div id=\"quando\">Adesso<br>".round(($current[0]->temp_f['data']*1-32)*5/9)." °C</div>\n";
$Adesso.= "</div>\n";
/*Per SMARTY*/
echo $Adesso;
foreach ($forecast_list as $forecast) {
$Altri_giorni[] = "<div id=\"cont_tempo\"><img id=\"img_tempo\" border=\"0\" src=\"http://www.google.com".$forecast->icon['data']."\" alt=\"". $forecast->condition['data']."\" />\n<div id=\"quando\">".$this->traduci($forecast->day_of_week['data'])."<br>".round(($forecast->low['data']*1-32)*5/9)." - ".round(($forecast->high['data']*1-32)*5/9)." °C</div>\n";
}
foreach ($Altri_giorni as $giorni) {
echo $giorni;
}
}
public function __construct() {
$this->day_of_week["Sun"]="Domenica";
$this->day_of_week["Mon"]="Lunedì";
$this->day_of_week["Tue"]="Martedì";
$this->day_of_week["Wed"]="Mercoledì";
$this->day_of_week["Thu"]="Giovedì";
$this->day_of_week["Fri"]="Venerdì";
$this->day_of_week["Sat"]="Sabato";
}
private function traduci($stringa) {
return $this->day_of_week["$stringa"];
}
private function load_file($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
$out = curl_exec($ch);
curl_close($ch);
return $out;
}
}
function cheTempoCheFa($citta) {
$t=new Previsioni();
$t->show($citta);
}
?>
EDIT
L'ho provato e funziona.