日期:2012-05-12  浏览次数:20476 次

写得一个php天气小偷程

<?php
/***
天气预报
***/
function readAll($location)
{
 $MAX_RETRY_NUM = 3;
 if(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.0\r\n";
  $request .= "Host: $host\r\n";
  $request .= "Accept: */*\r\n";
  $request .= "Connection: close\r\n";
  $request .= "User-Agent: superspice"s BOT\r\n\r\n";
  $retry = 0;
  $do = false;
  do
  {
   if(@!$socket =fsockopen($host, $port, &$errMsg, &$errCode ))
   {
    return false;
   }
   fwrite($socket, $request);
   $flag = true;
   $header = "";
   $body = "";
   while(!feof($socket))
   {
    $line = fgets($socket, 128);
    if($flag)
    {
     if(trim(chop($line)) == "")
     {
      $flag = false;
     }
     else
     {
      $header .= $line;
     }
    }
    else
    {
     $body .= $line;
    }
   }
   if(preg_match("/Content-Length: (\d+)/", $header, $out))
   {
    $header_length = $out[1];
    if($header_length != strlen($body))
    {
     $do = true;
    }
    else
    {
     $do = false;
    }
   }
   if(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);
 if(!$VaX1Tem)
 {
  return false;
 }
 settype($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);
 //天气
 $Arr