Nothing found, sorry. Try another search term. Maybe wunderground has no weather data on this place.
"; echo "Please use english Terms! Thanks!
"; } } // 2. has user selected a place if(isset($_REQUEST["placeFound"])) { $placeFound = $_REQUEST["placeFound"]; } // 2.1. no place selected -> do nothing // 2.2. user has selected a place: display 3 day weather forecast of that place if(empty($placeFound)) { if(empty($placesFound)) { $placeFound = "00000.1.10838"; // default is ulm } else { $placeFound = $places_array[0]->zmw; // use the first hit in the searchlist } } $json_string = curl_download("http://api.wunderground.com/api/YOUR-API-KEY-HERE/forecast/conditions/alerts/lang:US/q/zmw:".$placeFound.".json"); // $json_string = curl_download("json.txt"); // for offline testing only $parsed_json = json_decode($json_string); if(isset($parsed_json)) { if(!empty($parsed_json)) { if(isset($parsed_json->current_observation)) { if(!empty($parsed_json->current_observation)) { // current conditions $location = $parsed_json->{'current_observation'}->{'display_location'}->{'full'}; $temp_c = $parsed_json->{'current_observation'}->{'temp_c'}; $relative_humidity = $parsed_json->{'current_observation'}->{'relative_humidity'}; $wind_direction = $parsed_json->{'current_observation'}->{'wind_dir'}; $weather = $parsed_json->{'current_observation'}->{'weather'}; $wind_speed = $parsed_json->{'current_observation'}->{'wind_kph'}."km/h"; // forecast $forecast = $parsed_json->{'forecast'}->{'txt_forecast'}->{'forecastday'}; $simpleforecast = $parsed_json->{'forecast'}->{'simpleforecast'}->{'forecastday'}; $Today = printDay(getDay(0),"Prediction Today:"); $Tomorrow = printDay(getDay(1),"Prediction Tomorrow:"); $DayAfterTomorrow = printDay(getDay(2),"Prediction the Day after Tomorrow:"); echo "Current: $weather
Temp: $temp_c\n °C
Wind from: $wind_direction\n with speed: ".$wind_speed."
$Today
"; echo "$Tomorrow
"; echo "$DayAfterTomorrow
"; } else { echo 'I am sorry, we are out of wunderground-tickets! (the free service only allows a certain amount of requests per day. http://www.wunderground.com/weather/api/d/terms.html'; } } } } /* DayNumber is 0 = today, 1 = tomorrow, 2 = day after tomorrow... max 6 */ function getDay($DayNumber) { global $forecast, $simpleforecast; $result = null; $day = $forecast[$DayNumber]; $result['dayofweek'] = $day->{'title'}; $result['text'] = $day->{'fcttext_metric'}; $day_array = explode('.',$result['text']); $result['forecast_weather'] = $simpleforecast[$DayNumber]->{'conditions'}; // "conditions": "Teils Wolkig", $result['icon'] = $simpleforecast[$DayNumber]->{'icon_url'}; // "icon_url": "http://icons-ak.wxug.com/i/c/k/partlycloudy.gif", $result['forecast_high'] = "MaxTemp: ".$simpleforecast[$DayNumber]->{'high'}->{'celsius'}."°C"; $result['forecast_low'] = "LowTemp: ".$simpleforecast[$DayNumber]->{'low'}->{'celsius'}."°C"; $result['forecast_humidity'] = "Humidity: ".$simpleforecast[$DayNumber]->{'avehumidity'}."%"; $result['forecast_wind'] = "WindSpeed of: ".$simpleforecast[$DayNumber]->{'avewind'}->{'kph'}."km/h"; $result['forecast_winddirection'] = $simpleforecast[$DayNumber]->{'avewind'}->{'dir'}; // Südwest $result['forecast_rainrisk'] = "Probability of Rain: ".$simpleforecast[$DayNumber]->{'pop'}."%"; // probability of precipitation = regenwahrscheinlichkeit return $result; } function printDay($day,$title) { return "
$title
".$day['forecast_weather']."
".$day['forecast_high']."
".$day['forecast_low']."
".$day['forecast_rainrisk']."
Wind from
".$day['forecast_winddirection']."
with
".$day['forecast_wind']."