<?php
//error_reporting(E_ALL|E_STRICT);
function website_wetter($ort="", $sprache="de",$icons_src="http://www.google.com"){
$station=$ort;
$api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.com/ig/api?weather=".$station."&hl=".$sprache)));
if(@is_null($api->weather->problem_cause->attributes()->data) === false){
return false;
}
$wetter = array();
$wetter['stadt'] = $api->weather->forecast_information->city->attributes()->data;
$wetter['datum'] = $api->weather->forecast_information->forecast_date->attributes()->data;
$wetter['zeit'] = $api->weather->forecast_information->current_date_time->attributes()->data;
$wetter[0]['zustand'] = $api->weather->current_conditions->condition->attributes()->data;
$wetter[0]['temperatur'] = $api->weather->current_conditions->temp_c->attributes()->data;
$wetter[0]['luftfeuchtigkeit'] = $api->weather->current_conditions->humidity->attributes()->data;
$wetter[0]['wind'] = $api->weather->current_conditions->wind_condition->attributes()->data;
$wetter[0]['icon'] = $icons_src.$api->weather->current_conditions->icon->attributes()->data;
$i = 1;
foreach($api->weather->forecast_conditions as $weather){
$wetter[$i]['wochentag'] = $weather->day_of_week->attributes()->data;
$wetter[$i]['zustand'] = $weather->condition->attributes()->data;
$wetter[$i]['tiefsttemperatur'] = $weather->low->attributes()->data;
$wetter[$i]['hoechsttemperatur'] = $weather->high->attributes()->data;
$wetter[$i]['icon'] = $icons_src.$weather->icon->attributes()->data;
$i++;
}
return $wetter;
}
function printWeather($ret){
$re= "<div class=\"item\" style=\"float:left;width:230px;\">Wetter in <strong>".htmlspecialchars(utf8_decode($ret['stadt'][0]))."</strong><br />Aktuell um ".date('G:i:s',time()).'<br />';
$re .= '<div style="float:left;height:60px;margin-right:15px;"><img src="'.$ret[0]['icon'].'" /></div>';
foreach($ret[0] as $key=>$wert){
switch ($key) {
case 'zustand':
$re .= 'Zustand: '.htmlspecialchars(utf8_decode($wert)).'<br />';
break;
case 'temperatur':
$re .= 'Temperatur: '.htmlspecialchars(utf8_decode($wert)).' ?<br />';
break;
case 'luftfeuchtigkeit':
$re .= htmlspecialchars(utf8_decode($wert)).'<br />';
break;
case 'icon':
break;
default:
$re .= htmlspecialchars(utf8_decode($wert)).'<br />';
break;
}
}
$re .= '</div>';
$re .= '<div class="item" style="width:99%;">';
$re .= 'Wettervorhersage für die nächsten Tage:<br />';
for($i=1;$i<count($ret);$i++){
if(!array_key_exists($i,$ret)){
break;
}else{
$re .= '<div style="display:inline;float:left;width:230px;">';
$re .= $ret[$i]['wochentag'].'<br />';
$re .= '<div style="float:left;height:60px;margin-right:15px;"><img src="'.$ret[$i]['icon'].'" /></div>';
foreach($ret[$i] as $key=>$wert){
switch ($key) {
case 'zustand':
$re .= 'Zustand: '.htmlspecialchars(utf8_decode($wert)).'<br />';
break;
case 'tiefsttemperatur':
$re .= 'Tiefst-Temperatur: '.htmlspecialchars(utf8_decode($wert)).' ?<br />';
break;
case 'hoechsttemperatur':
$re .= 'Höchst-Temperatur: '.htmlspecialchars(utf8_decode($wert)).' ?<br />';
break;
default:
break;
}
}
$re .= '</div>';
}
}
$re .= '</div>';
$re .= '<span style="display:block;clear:both;"> </span>';
return $re;
}
$loc = array('Stockholm','Oslo','Trondheim','Alta','Narvik','Kiruna');
echo "<html>
<head>
<title>Wetter @ MEINE_SEITE</title>
<style type=\"text/css\">
.item {
font-family:verdena;
font-size:0.7em;
margin-left:20px;
}
</style>
</head>
<body>";
if(!isset($_GET['loc']) || $_GET['loc'] == ''){
foreach($loc as $wert){
website_wetter($wert) === false?$t='':$t=printWeather(website_wetter($wert));
echo $t;
}
}else{
foreach($_GET as $key=>$wert){
if(strpos($key,'loc') !== false){
website_wetter($wert) === false?$t='':$t=printWeather(website_wetter($wert));
echo $t;
}
}
}
echo '</body></html>';
?>