首页 > php框架 > 如何实现PHP抓取天气预报的功能

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

我们可以使用

PHP抓取天气预报绝对精简代码

  1. <form method="post"> 
  2. <input name="a" type="text" id="a" /> 
  3. <input type="submit" name="Submit" value="查" /> 
  4. < /form> 
  5. < ?php  
  6. $city = $_REQUEST["a"];  
  7. if ($city=="")  
  8. {  
  9. $city="菏泽";  
  10. }  
  11. $url = http://www.baidu.com/s?wd=.$city.天气;   
  12. $lines_array = file($url);   
  13. $lines_string = implode(, $lines_array);   
  14. eregi("今天((.*)今日气象指数", $lines_string, $body);   
  15. $body[0]=strip_tags($body[0]);  
  16. $body[0] = str_replace(" 今日气象指数","",$body[0]);  
  17. $body[0] = str_replace(" ","",$body[0]);  
  18. echo $city.$body[0];  
  19. ?> 

以上代码示例就是PHP抓取天气预报的实现方法。


本文链接:http://www.phprm.com/frame/php1003791.html

收藏随意^^请保留教程地址.

标签:none

发表留言