Skip to content

Instantly share code, notes, and snippets.

@danoc
Created January 16, 2012 20:50
Show Gist options
  • Save danoc/1622983 to your computer and use it in GitHub Desktop.
Save danoc/1622983 to your computer and use it in GitHub Desktop.
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