如何实现PHP抓取天气预报的功能
我们可以使用
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抓取天气预报的实现方法。
本文链接:http://www.phprm.com/frame/php1003791.html
收藏随意^^请保留教程地址.