Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use SimpleXML and Google's (unofficial) Weather API to display the current temperature for a city.
<?php
// Use SimpleXML and Google's (unofficial) Weather API
//to display the current temperature for a city.
$zip = 13902; // change to desired city
$weather = simplexml_load_file('http://www.google.com/ig/api?weather='.$zip);
$city = $weather->weather->forecast_information->city['data']; // city name
$degrees = $weather->weather->current_conditions->temp_f['data']; // current temperature
// display the current temperature and city name
echo $degrees."&deg; - ".$city;
?>
@danoc
Copy link
Author

danoc commented Jan 20, 2013

Google shut down their (unofficial) weather API, so this no longer works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment