Home >Backend Development >PHP Tutorial >Google API php code to obtain current weather information

Google API php code to obtain current weather information

WBOY
WBOYOriginal
2016-07-25 09:00:021128browse
PHP obtains the current weather information through Google API, which only requires 3 lines of code. When using it, you only need to replace ADDRESS with the city you want.

The code is as follows:

<?php
/**
 * Google API应用
 * 获取某城市的当天天气
 * by http://bbs.it-home.org
*/
$xml = simplexml_load_file('http://www.google.com/ig/api?weather=ADDRESS'); 
  $information = $xml->xpath("/xml_api_reply/weather/current_conditions/condition"); 
  echo $information[0]->attributes();
?>
Articles you may be interested in: An example of php weather forecast code PHP calls yahoo sina api weather forecast implementation code PHP example code for calling Google Weather API


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn