文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PHP天气预报小偷07年版

PHP天气预报小偷07年版

时间:2007-02-18  来源:PHP爱好者

请大家多多指教!
CODE:
[复制到剪切板]
<?
/************************************************************************
名称:天气预报小偷
功能:每天读取新浪网上的天气情况并保存到本地,然后再从本地读取显示
开发:n3tl04d QQ:10492315 1妹儿:n3tl04d[at]gmail.com [url]http://smboy.bokee.com[/url]
更新日期: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";
        }
    }
?>  php爱好 者站 http://www.phpfans.net php基础|php进阶|php模板.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载