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

如何实现PHP抓取天气预报的功能

2013-09-04 21:50 393 查看
我们可以使用
PHP抓取天气预报绝对精简代码
< form method="post"> < input name="a" type="text" id="a" /> < input type="submit" name="Submit" value="查" /> < /form> < ?php $city = $_REQUEST["a"]; if ($city=="") { $city="菏泽"; } $url = 'http://www.baidu.com/s?wd='.$city.'天气'; $lines_array = file($url); $lines_string = implode('', $lines_array); eregi("今天((.*)今日气象指数", $lines_string, $body); $body[0]=strip_tags($body[0]); $body[0] = str_replace(" 今日气象指数","",$body[0]); $body[0] = str_replace(" ","",$body[0]); echo $city.$body[0]; ?> 以上代码示例就是PHP抓取天气预报的实现方法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: