首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > PHP >

php抓取天气预报接口数据有关问题,求指点

2013-03-17 
php抓取天气预报接口数据问题,求指点国家气象局免费天气预报接口(沈阳):http://www.weather.com.cn/data/c

php抓取天气预报接口数据问题,求指点
国家气象局免费天气预报接口(沈阳):http://www.weather.com.cn/data/cityinfo/101010100.html
这个接口提供了一个json格式的天气预报数据。
不知道用php怎么得到这个json,在网上找到了以下代码
php抓取天气预报接口数据有关问题,求指点
但其中的httpGetRequest函数是个自定义函数,而且网上并没有放出这个函数的原型!请高手指点! json 天气预报
[解决办法]

$url = 'http://www.weather.com.cn/data/cityinfo/101070101.html';
$s = file_get_contents($url);
print_r(json_decode($s, true));
Array
(
    [weatherinfo] => Array
        (
            [city] => 沈阳
            [cityid] => 101070101
            [temp1] => 10℃
            [temp2] => -2℃
            [weather] => 多云
            [img1] => d1.gif
            [img2] => n1.gif
            [ptime] => 08:00
        )

)

[解决办法]
httpGetRequest无需理会,反正目的就是把文本抓下来,只是用了什么手段而已,你完全可以自写
直接获取就按版主给的file_get_contents,想省点流量就用curl或者socket发送压缩请求
先用 file_get_contents 把工作完成了,等有时间学习了curl, socket...再回头优化吧

热点排行