//百度天氣接口API
$location = "北京"; //地區
$ak = "5slgyqGDENN7Sy7pw29IUvrZ"; //秘鑰,需要申請,百度為了防止頻繁請求
$weatherURL = "http://api.map.baidu.com/telematics/v3/weather?location=$location&output=json&ak=$ak";
$ch = curl_init($weatherURL) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 獲取數據返回
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); // 在啟用 CURLOPT_RETURNTRANSFER 時候將獲取數據返回
$result = curl_exec($ch);
echo $result;