$httpCall = 'www.google.com/ig/api?weather=' . $postal;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $httpCall);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
if (strpos($output, 'problem_cause') === false) {
$xml = new SimpleXMLElement($output);
$weather = $xml[0]->weather->current_conditions;
echo 'Current Temperature: ' . $weather->temp_f;
}
PHP Get current temperature for a zip code
Leverages Google's weather data API to fetch the current temperature for a given zip/postal code.
Snippet Viewed 10020 times.
Share your PHP code snippets:
- Get some recognition & a link back to your site.
- Create your own code library.
- Help your fellow developers, as they have helped you.
Related Articles