PHP天气预报小偷代码

<?

*************************************************************************/

@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=广州” ;

    $content = file_get_contents($url);

    preg_match_all(‘/<div>(.+?)</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”;

    $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″>

      <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 >

    <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>

    <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”;

        }

    } 

?>

发表评论

邮箱地址不会被公开。 必填项已用*标注

click to changeSecurity Code