Skip to content

Instantly share code, notes, and snippets.

@cam-gists
Created August 20, 2012 16:07
Show Gist options
  • Save cam-gists/3405399 to your computer and use it in GitHub Desktop.
Save cam-gists/3405399 to your computer and use it in GitHub Desktop.
PHP: Google Weather API
<?php
function GetWeather($state,$country,$langauge,$waetherIcons){
// auf der Basis von http://www.web-spirit.de/webdesign-tutorial/9/Wetter-auf-eigener-Website-mit-Google-Weather-API
$api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.com/ig/api?weather=".$state."-".$country."&hl=".$langauge)));
// $trans = array("ä" => "ä", "Ä" => "Ä", "ü" => "ü", "Ü" => "Ü", "ö" => "ö", "Ö" => "Ö", "ß" => "ß");
$trans = array("ü" => "ü", "ö" => "ö", "ä" => "ä", "ß" => "ß");
$weather = array();
$i = 1;
foreach($api->weather->forecast_conditions as $GoogleWeather){
$waetherIcons = $GoogleIcons = "/ig/images/weather/";
$weather[$i]['zustand'] = strtr(strtolower($GoogleWeather->condition->attributes()->data), $trans);
$weather[$i]['tiefsttemperatur'] = $GoogleWeather->low->attributes()->data;
$weather[$i]['hoechsttemperatur'] = $GoogleWeather->high->attributes()->data;
$weather[$i]['icon'] = str_replace($GoogleIcons, $waetherIcons, $GoogleWeather->icon->attributes()->data);
$i++;
}
return $weather;
}
GetWeather('ca', 'usa', 'en', 'true');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment