1. 程式人生 > >獲取天氣信息

獲取天氣信息

code close nts con pan ini encoding color eat

//獲取天氣
function getweather($city){  //傳入需要查詢的城市
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, "http://wthrcdn.etouch.cn/weather_mini?city=$city");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //        curl_setopt($ch,CURLOPT_ENCODING ,‘gzip‘);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout
); $file_contents = curl_exec($ch); curl_close($ch); return gzdecode($file_contents); }

獲取天氣信息