header("Content-Type: text/html; charset=utf-8"); #require_once('print_rf.func.php'); class GoogleWeather { var $basUrl = 'http://www.google.com/ig/api?weather='; var $lng = 'de'; function setLng($lng) { $this->lng = $lng; } function get($loc) { $XmlStr = file_get_contents($this->basUrl.urlencode($loc).'&hl='.$this->lng); $Xml = simplexml_load_string(utf8_encode($XmlStr)); $W = $Xml->weather; $this->Data['info']['city'] = (string)$W->forecast_information->city['data']; $this->Data['info']['today'] = strtotime((string)$W->forecast_information->forecast_date['data']); $this->Data['info']['time'] = strtotime((string)$W->forecast_information->current_date_time['data']); if(!$this->Data['info']['city']) { $this->Error = '"'.$loc.'" not found'; return false; } // today $w = array(); foreach($W->current_conditions->children() as $k => $v) { $w[$k] = (string)$v['data']; } $this->Data['current'] = $w; $this->Data['current']['updated'] = $this->Data['info']['time']; // forecast $w = array(); $i = 0; foreach($W->forecast_conditions as $k1 => $v1) { $t = $this->Data['info']['today']+($i*86400); foreach($v1->children() as $k2 => $v2) { $w[$t][$k2] = (string)$v2['data']; } $i++; } $this->Data['forecast'] = $w; return $this->Data; } } if(!$_GET['loc']) { $_GET['loc'] = "Bolzano"; } if(!$_GET['lng']) { $_GET['lng'] = "de"; } $Gw = new GoogleWeather; $Gw->setLng($_GET['lng']); $Gw->get($_GET['loc']); ?>