查看: 4737|回复: 0
打印 上一主题 下一主题

PHP天气预报小偷07年版

[复制链接]
跳转到指定楼层
1#
发表于 2007-10-5 14:43:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
<?
/************************************************************************
名称:天气预报小偷
功能:每天读取新浪网上的天气情况并保存到本地,然后再从本地读取显示
更新日期:2007年1月8日
*************************************************************************/
/*******************看weather.txt的修改时间是否为当天,如果是昨天的就要上网抓结果***********/
     $tmp = filemtime("weather.txt");
    $tt1=date("Ymd",$tmp)."<br>";
    $tt2=date("Ymd");
    if ($tt1<$tt2) {
    //echo "要抓结果";
    unlink("weather.txt");
    $lines = file ('http://php.weather.sina.com.cn/search.php?city=广州');
  // 在数组中循环,显示 html 的源文件并加上行号。

  foreach ($lines as $line_num => $line) {   
    if ($line_num==247||$line_num==270){
    //echo "Line #<b>{$line_num}</b> :  $line<br>n";
     $a1=strip_tags($line);//处理多余代码
        $handle = fopen ("weather.txt", "a");
           fwrite($handle, $a1);
         fclose($handle);
     }
   }
   echo "<meta http-equiv="refresh" content="1">";
  
} else {
    // echo "直接从weather.txt读结果";

    $filename="weather.txt";
    @$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="252" 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">
      <div align="center">未来48小时天气预报</div></td>
  </tr>
  <tr bgcolor="#0066FF">
    <td width="54" height="21">
      <div align="center"><font color="#FFFFFF">时间</font></div></td>
    <td width="88">
      <div align="center"><font color="#FFFFFF">天气</font></div></td>
    <td width="90">
      <div align="center"><font color="#FFFFFF">温度</font></div></td>
  </tr>
  <tr >
    <td height="19" >
      <div align="center"> 今天</div></td>
    <td>
     
      <div align="center"><?=$today[0]?></div></td>
    <td>
     
      <div align="center"><?=$today[1]?></div></td>
  </tr>
  <tr>
    <td height="18">
      <div align="center">明天</div></td>
    <td>
     
      <div align="center"><?=$tomo[0]?></div></td>
    <td>
   
      <div align="center"><?=$tomo[1]?></div></td>
  </tr>
</table>
<?
   
        } else {
            echo "无法读取所需文件!!n";
        }
    }
?>
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表