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.
$httpCall = '' . $postal;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $httpCall);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
if (strpos($output, 'problem_cause') === false) {
	$xml = new SimpleXMLElement($output);
	$weather = $xml[0]->weather->current_conditions;
	echo 'Current Temperature: ' . $weather->temp_f;
Snippet Viewed 10593 times.

Share your PHP code snippets:

  • Get some recognition & link back to your site.


Submit | Browse

Most Recent php snippets

Most Viewed