<?php
//网上的天气接口有很多,但是大多也都是不更新的或则禁用的,可谓变幻无常,近期使用的这个感觉不错
header('content-type:text/html;charset=utf-8');
$ch = curl_init();
$city = '蚌埠';
$url = 'http://api.map.baidu.com/telematics/v3/weather?location='.$city.'&output=json&ak=6tYzTvGZSOpYB5Oc2YGGOKt8';
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 执行HTTP请求
curl_setopt($ch , CURLOPT_URL , $url);
$res = curl_exec($ch);
$result = json_decode($res,true);
echo "<pre>";
var_dump($result);
?>
详细解释链接:http://blog.csdn.net/ztxnight/article/details/44153257