标签归档:天气预报

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

        }

    } 

?>

天气预报小偷PHP代码

<?
/***

***/
function readAll($location)
{
 $MAX_RETRY_NUM = 3;
 (preg_match(“/(http://)?([^/|:]+)(:d{1,5})?(/.+)?/”, $location, $url))
 {
  list(,,$host,$port,$path) = $url;
  $port = preg_replace(“/:/”, “”, $port);
  $port = strlen($port) ? $port : 80;
  $path = strlen($path) ? $path : “/”;
  $request  = “GET $path HTTP/1.0rn”;
  $request .= “Host: $hostrn”;
  $request .= “Accept: */*rn”;
  $request .= “Connection: closern”;
  $request .= “User-Agent: superspice’s BOTrnrn”;
  $retry = 0;
  $do = false;
  do
  {
    (!$socket =fsockopen($host, $port, &$errMsg, &$errCode ))
   {
    return false;
   }
   fwrite($socket, $request);
   $flag = true;
   $header = “”;
   $body = “”;
   while(!feof($socket))
   {
    $line = fgets($socket, 128);
    ($flag)
    {
    (trim(chop($line)) == “”)
     {
      $flag = false;
     }
      
     {
      $header .= $line;
     }
    }
    
    {
     $body .= $line;
    }
   }
   (preg_match(“/Content-Length: (d+)/”, $header, $out))
   {
    $header_length = $out[1];
    ($header_length != strlen($body))
    {
     $do = true;
    }
        {
     $do = false;
    }
   }
   (is_resource($socket))
   {
    fclose($socket);
   }
   $retry ++;
  }while($do && $retry<$MAX_RETRY_NUM);
 }
 return $body;
}
function get_weather()
{
 $TqUrl=”http://www.ttqx.com.cn/forecast/area_weather.asp?city_name=合肥&zhou=yz”;
 $VaX1Tem=readAll($TqUrl);
 (!$VaX1Tem)
 {
  return false;
 }
 type($ArrayTq,”array”);
 $ArrayTq=explode(“<!–天气预报开始–>”,$VaX1Tem);
 $ArrayTq=explode(“<!–天气预报结束–>”,$ArrayTq[1]);
 $flash = explode(“<object classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″”,$ArrayTq[0]);
 $flash = “<object classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″”.$flash[1];
 $flash = explode(“</EMBED></object>”,$flash);
 $flash = $flash[0].”</EMBED></object>”;
 $pattern = array(“/images/weather/i”,”/WIDTH=”65″ HEIGHT=”70″/i”);
 $replace = array(“http://www.ttqx.com.cn/forecast/images/weather”,”WIDTH=”51″ HEIGHT=”55″”);
 $flash = preg_replace($pattern,$replace,$flash);
 //天气
 $ArrayTqTem2=explode(‘<tr><td>’,$ArrayTq[0]);
 $ArrayTqTem2=explode(‘</td></tr>’,$ArrayTqTem2[1]);
 //$ArrayTqTem2=explode(‘<td>’,$ArrayTqTem2[0]);
 $ArrayTqTem2=$ArrayTqTem2[0];
 //风力
 $ArrayTqTem3=explode(‘<tr><td>’,$ArrayTq[0]);
 $ArrayTqTem3=explode(‘</td></tr>’,$ArrayTqTem3[2]);
 //$ArrayTqTem3=explode(‘<td>’,$ArrayTqTem3[0]);
 $ArrayTqTem3=$ArrayTqTem3[0];
 //温度
 $ArrayTqTem4=explode(‘<tr><td>’,$ArrayTq[0]);
 $ArrayTqTem4=explode(‘</td></tr>’,$ArrayTqTem4[3]);
 //$ArrayTqTem4=explode(‘<td>’,$ArrayTqTem4[0]);
 $ArrayTqTem4=$ArrayTqTem4[0];
( !$ArrayTqTem2 or !$ArrayTqTem3 or !$ArrayTqTem4)
 {
  return false;
 }
 //$TqVar=$ArrayTqTem2.”,”.$ArrayTqTem3.”<br>气温:”.$ArrayTqTem4;
 $weather[0]=$flash;
 $weather[1]=$ArrayTqTem2;
 $weather[2]=$ArrayTqTem3;
 $weather[3]=$ArrayTqTem4;
 return $weather;
}
$weather = get_weather();
?>

上面写的是php文件,你没有echo当然不能正常显示啦

<?php
error_reporting(0);
include_once (“../include/weather.php”);
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<title>天气预报</title>
<style>
html,body {margin:0;padding:0; font-size:12px;}
div {width:178px; height:58px;position:relativ;position:relative}
img {width:178px; height:58px; z-index:1;position:absolute; border:0}
object { margin-top:2px; margin-left:8px;}
span{position:absolute;top:2px;right:12px;}
li{font-family:Verdana,宋体;list-style:none;margin-top:3px; letter-spacing:1px;}
</style>
</head>
<body>
<div>
<a href=”http://www.ttqx.com.cn/tqyb/” target=”_blank”><img src=”http://www.maqie.com/wp-content/uploads/auto_save_image/2011/01/0502051Co.gif” /></a><?php echo $weather[0]; ?><span><li><?php echo $weather[1]; ?></li> <li><?php echo $weather[2]; ?></li> <li><?php echo $weather[3]; ?></li></span>
</div>
</body>
</html>