//获取天气 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); }
原文地址:https://www.cnblogs.com/zrn-php/p/9447913.html
时间: 2024-10-28 13:31:51