Home > php教程 > php手册 > PHP实例教程:天气预报小偷PHP代码

PHP实例教程:天气预报小偷PHP代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-21 08:56:44
Original
1608 people have browsed it

写得一个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 }
 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(" $flash = " $flash = explode("",$flash);
 $flash = $flash[0]."
";
 $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("

",$ArrayTq[0]);
 $ArrayTqTem2=explode("",$ArrayTqTem2[1]);
 //$ArrayTqTem2=explode("",$ArrayTqTem2[0]);
 $ArrayTqTem2=$ArrayTqTem2[0];
 //风力
 $ArrayTqTem3=explode(" ",$ArrayTq[0]);
 $ArrayTqTem3=explode("",$ArrayTqTem3[2]);
 //$ArrayTqTem3=explode("",$ArrayTqTem3[0]);
 $ArrayTqTem3=$ArrayTqTem3[0];
 //温度
 $ArrayTqTem4=explode(" ",$ArrayTq[0]);
 $ArrayTqTem4=explode("",$ArrayTqTem4[3]);
 //$ArrayTqTem4=explode("",$ArrayTqTem4[0]);
 $ArrayTqTem4=$ArrayTqTem4[0];
 if( !$ArrayTqTem2 or !$ArrayTqTem3 or !$ArrayTqTem4)
 {
  return false;
 }
 //$TqVar=$ArrayTqTem2.",".$ArrayTqTem3."
气温:".$ArrayTqTem4;
 $weather[0]=$flash;
 $weather[1]=$ArrayTqTem2;
 $weather[2]=$ArrayTqTem3;
 $weather[3]=$ArrayTqTem4;
 return $weather;
}
$weather = get_weather();
?>

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

error_reporting(0);
include_once ("../include/weather.php");
?>




澶╂
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template