<?php
//Wetter in Waldfeucht
$url = "http://rss.wunderground.com/auto/rss_full/global/stations/10500.xml";
$content = implode("", file($url));
preg_match_all("/\<item>(.*?)\<\/item\>/si", $content, $results);
preg_match("/\<description\>(.*?)\<\/description\>/si", $results[1][0], $desc);
$arr = explode(" | ",$desc[1]);
/*
* echo '<pre>' . print_r($arr, true) . '</pre>';
*
* Array
* (
* [0] => Temperature: 86°F / 30°C
* [1] => Humidity: 74%
* [2] => Pressure: 29.83in / 1010hPa
* [3] => Conditions: Partly Cloudy
* [4] => Wind Direction: ESE
* [5] => Wind Speed: 5mph / 7km/h
* [6] => Updated: 10:00 PM PHT
* )
*/
//Temperatur
preg_match("/Temperature: (.*?)F \/ (.*?)C/si", $arr[0], $str);
$wetter['temp'] = $str['2'];
//Wetterbedingung
preg_match("/Conditions: (.*)/si", $arr[3], $str);
$wetter['verh'] = $str['1'];
//Übersetze Wetterbedingung ins Deutsche
switch($wetter['verh'])
{
case 'Partly Cloudy':
$wetter['verh'] = 'Teils wolkig';
break;
case 'Mostly Cloudy':
$wetter['verh'] = 'Überwiegend wolkig';
break;
case 'Scattered Clouds':
$wetter['verh'] = 'Teils wolkig';
break;
case 'Overcast':
$wetter['verh'] = 'Bewölkt';
break;
case 'Clear':
$wetter['verh'] = 'Heiter';
break;
case 'Fog':
$wetter['verh'] = 'Nebel';
break;
case 'Heavy Fog':
$wetter['verh'] = 'Starker Nebel';
break;
case 'Light Fog':
$wetter['verh'] = 'Leicher Nebel';
break;
case 'Thunderstorm':
$wetter['verh'] = 'Gewitter';
break;
case 'Light Thunderstorm':
$wetter['verh'] = 'Leichte Gewitter';
break;
case 'Heavy Thunderstorm':
$wetter['verh'] = 'Starke Gewitter';
break;
case 'Thunderstorms and Rain':
$wetter['verh'] = 'Gewitter mit Regen';
break;
case 'Light Thunderstorms and Rain':
$wetter['verh'] = 'Leichte Gewitter mit Regen';
break;
case 'Light Rain Showers':
$wetter['verh'] = 'Leichte Regenschauer';
break;
case 'Heavy Rain Showers':
$wetter['verh'] = 'Starke Regenschauer';
break;
case 'Light Rain':
$wetter['verh'] = 'Leichter Regen';
break;
case 'Haze':
$wetter['verh'] = 'Trübe';
break;
case 'Patches of Fog':
$wetter['verh'] = 'Nebelfelder';
break;
case 'Unknown Percipitation':
$wetter['verh'] = 'Ung. Niederschläge';
break;
case 'Light Drizzle':
$wetter['verh'] = 'Leichter Sprühregen';
break;
case 'Mist':
$wetter['verh'] = 'Leicher Nebel';
break;
case 'Light Rain Mist':
$wetter['verh'] = 'Leicher Nebel';
break;
default:
$wetter['verh'] = $wetter['verh'];
break;
}
//Luftfeuchtigkeit
preg_match("/Humidity: (.*)/si", $arr[1], $str);
$wetter['feuchte'] = $str['1'];
//Windrichtung
preg_match("/Wind Direction: (.*)/si", $arr[4], $str);
$wetter['windr'] = $str['1'];
//Übersetze Windrichtung ins Deutsche
switch($wetter['windr'])
{
case 'North':
$wetter['windr'] = 'Nord';
break;
case 'East':
$wetter['windr'] = 'Ost';
break;
case 'South':
$wetter['windr'] = 'Süd';
break;
case 'West':
$wetter['windr'] = 'West';
break;
case 'SE':
$wetter['windr'] = 'SO';
break;
case 'SSE':
$wetter['windr'] = 'SSO';
break;
case 'NE':
$wetter['windr'] = 'NO';
break;
case 'ESE':
$wetter['windr'] = 'OSO';
break;
case 'NNE':
$wetter['windr'] = 'NNO';
break;
case 'ENE':
$wetter['windr'] = 'ONO';
break;
case 'Calm':
$wetter['windr'] = 'Windstill';
break;
default:
$wetter['windr'] = $wetter['windr'];
break;
}
//Windgeschwindigkeit
preg_match("/Wind Speed: (.*?)mph \/ (.*?)km\/h/si", $arr[5], $str);
$wetter['windg'] = $str['2'];
//echo $wetter['temp'];
//echo $wetter['verh'];
//echo $wetter['windr'];
//echo $wetter['windg'];
//echo '<pre>' . print_r($wetter, true) . '</pre>';
?>
<html>
<head>
<title>Das Wetter in Waldfeucht</title>
</head>
<body>
<h2>Waldfeucht</h2>
<br>
<?php
echo $wetter['temp'];
echo $wetter['verh'];
echo $wetter['windg'];
echo $wetter['windr'];
echo $wetter['feuchte'];
?>
</body>
</html>