Jas*_*euw 12
如果您想在php应用程序中获取天气数据,则需要调用API.例如:http: //openweathermap.org/current
如上页所示,您可以按城市名称请求数据:在JSON api.openweathermap.org/data/2.5/weather?q=London,uk
您可以通过执行与此类似的操作来访问此数据:
<?php
$jsonurl = "http://api.openweathermap.org/data/2.5/weather?q=London,uk";
$json = file_get_contents($jsonurl);
$weather = json_decode($json);
$kelvin = $weather->main->temp;
$celcius = $kelvin - 273.15;
?>
Run Code Online (Sandbox Code Playgroud)
现在$开尔文是开尔文的温度和Celcius的$ celcius!
我希望这会对你有所帮助,如果这不是你的意思,请尝试更具体!
| 归档时间: |
|
| 查看次数: |
14854 次 |
| 最近记录: |