您的位置:首页 > 编程语言 > PHP开发

php获取天气

2017-05-23 09:14 148 查看
public function getWeather()
{
//方法1:
$url = 'http://wthrcdn.etouch.cn/weather_mini?city=北京';
$html = file_get_contents($url);
echo gzdecode($html);
// 方法2
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, 'http://wthrcdn.etouch.cn/weather_mini?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);

echo gzdecode($file_contents);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php 天气