网站LOGO 200*100
会员登陆
首页网站建设软件下载精美图片三峡影院雁过留声网建论坛PHP开发组
数据库类 网站编程 网页设计 建站技巧 网站安全 流媒体类
专题栏目
最新热门文章
最新推荐文章
相关内容
没有相关文章
当前位置: 三峡网建  网站建设  网站编程  PHP  文章正文
PHP天气预报小偷——08年版     ★★★★
PHP天气预报小偷——08年版
作者:cqwzlb整… 文章来源:中国网管联盟 点击数: 更新时间:2008-2-29

<?php
/************************************************************************
名称:天气预报小偷
功能:每天读取新浪网上的天气情况并保存到本地,然后再从本地读取显示
开发:n3tl04d QQ:10492315 1妹儿:n3tl04d[at]gmail.com [url]http://smboy.bokee.com[/url]
更新日期:2007年11月22日
*************************************************************************/
@header("Content-Type:text/html;charset=gb2312");
 error_reporting(0);

/*******************看weather.txt的修改时间是否为当天,如果是昨天的就要上网抓结果***********/
     $tmp = filemtime("weather.txt");
    $tt1=date("Ymd",$tmp)."<br>";
    $tt2=date("Ymd");
    if ($tt1<$tt2) {
    //echo "要抓结果";
    unlink("weather.txt");
    $url = "http://php.weather.sina.com.cn/search.php?city=广州" ;
bitsCN.nET*中国网管博客

    $content = file_get_contents($url);
    preg_match_all('/<div class="Weather_TP">(.+?)<\/DIV>/si',$content,$result);
    for($i=0;$i<2;$i++){
        $x= strip_tags($result[1][$i])."\n";
        $handle = fopen ("weather.txt", "a");
            fwrite($handle, $x);
         fclose($handle);

      }
      listweather();
  
    } else {
        // echo "直接从weather.txt读结果";   
        listweather();
    }

    //天气显示函数
    function listweather() {
    $filename="weather.txt";
www_bitscn_com中国.网管联盟

    $handle=fopen($filename,"r");

    if ($handle) {   
        $contents=fread($handle,filesize($filename));
        fclose($handle);
        $cc=explode("\n",$contents);
        $today=explode(" ",$cc[0]);
        $tomo=explode(" ",$cc[1]);
?>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<table width="200" height="85"  cellspacing="0" bordercolordark="#FFFFFF" bordercolorlight="#000000" border="1" align="center" cellpadding="2">
  <tr bgcolor="#6b8ba8" style="color:FFFFFF">
    <td height="22" colspan="3">
bitsCN#com中国网管联盟


      <div align="center">未来48小时天气预报</div></td>
  </tr>
  <!--<tr bgcolor="#0066FF"> -->
  <tr >
    <td width="54" height="21">
      <div align="center"><font style="font-size=14px" color="#000000">时间</font></div></td>
    <td width="88">
      <div align="center"><font style="font-size=14px" color="#000000">天气情况</font></div></td>
    <td width="90">
      <div align="center"><font  style="font-size=14px" color="#000000">温度℃</font></div></td>
  </tr>
  <tr > www@bitscn@com
    <td height="19" >
      <div align="center"> <font style="font-size=14px">今天</font></div></td>
    <td>     
      <div align="center"><font style="font-size=14px"><?php echo $today[0]?></font></div></td>
    <td>    
      <div align="center"><font style="font-size=14px"><?php echo ereg_replace("℃","",$today[1])?>℃</font></div></td>
  </tr>
  <tr>
    <td height="18">
      <div align="center"><font style="font-size=14px">明天</font></div></td> bitsCN.nET*中国网管博客
    <td>
     
      <div align="center"><font style="font-size=14px"><?php echo $tomo[0]?></font></div></td>
    <td>     
      <div align="center"><font style="font-size=14px"><?php echo ereg_replace("℃","",$tomo[1])?>℃</font></div></td>
  </tr>
</table>
<?php
   
        } else {
            echo "无法读取天气记录!!\n";
        }
    } 
?>

本文来自: 中国网管联盟(bitsCN.com) 详细出处参考:http://www.bitscn.com/php/program/200711/120314.html

文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    设为首页 加入收藏 联系站长 友情链接 版权申明

    本站建议采用1024*768分辨率浏览. CopyRight(R)2006-2007 www.cqwzlb.com 渝ICP备07002351号All rights reserved 三峡网建版权所有 ! 内核:PowerEasy 2005 QQ:50079451