你所在的位置:首 页 >> php编程 >> 详细新闻页面


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

作者:zhirong1230 创建时间:2013-01-05 阅读次数:2208


      我们可以使用PHP语言实现许多种功能。今天我们就向大家介绍一下如何实现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抓取天气预报的实现方法。



    关键词(keywords):如何实现PHP抓取天气预报的功能

分享到: 更多


前一篇: 360通用php防护代码            后一篇:优化网页加载速度的方法

phpchina   php爱好者   php100    中国网管联盟   LAMP兄弟连   河北联合大学   胜芳趣团网   rss 联系我们 问题反馈
版权所有@:ABCMS新闻发布系统!
建议使用ie6、ie8和 ff 浏览器进行浏览 | 建议分辨率:1024x768
地址:唐山市路北区高新技术产业园区龙华道128号 | 邮编:63000| 邮箱:zhirong1230@yeah.net