Skip to content

Instantly share code, notes, and snippets.

@syropian
Created December 21, 2011 15:12
Show Gist options
  • Save syropian/1506360 to your computer and use it in GitHub Desktop.
Save syropian/1506360 to your computer and use it in GitHub Desktop.
Grabbing the current conditions and temperature with Google's weather API
<?php
$location = $_GET['q'];
$url = 'http://www.google.com/ig/api?weather='.urlencode($location);
$process = curl_init($url);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($process);
$xml = simplexml_load_string($response);
$temperature = $xml->weather->current_conditions->temp_c['data'].'&deg;C';
$conditions = $xml->weather->current_conditions->condition['data'];
echo $conditions.', '.$temperature;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment