Skip to content

Instantly share code, notes, and snippets.

@jhaus
Created January 4, 2011 23:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhaus/765627 to your computer and use it in GitHub Desktop.
Save jhaus/765627 to your computer and use it in GitHub Desktop.
Prints current + 3 day weather forecast - via: googleapihelp.com (slightly modified)
<?php
$weather_loc = 10001;
function getWeather( $weather_loc ) {
// weather data url, location based
$requestAddress = 'http://www.google.com/ig/api?weather=$weather_loc&hl=en';
// Parse XML
$xml_str = file_get_contents($requestAddress,0);
// Loops XML
$xml = new SimplexmlElement($xml_str);
$count = 0;
echo '<div id="weather">';
foreach($xml->weather as $item) {
foreach($item->forecast_conditions as $new) {
echo '<div class="weatherIcon">';
echo '<img src="http://www.google.com/' .$new->icon['data'] . '"/><br/>';
echo $new->day_of_week['data'];
echo '</div>';
}
}
echo '</div>';
}
getWeather();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment