Created
January 4, 2011 23:05
-
-
Save jhaus/765627 to your computer and use it in GitHub Desktop.
Prints current + 3 day weather forecast - via: googleapihelp.com (slightly modified)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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