PHP Example Tutorial: Weather Forecast thieves PHP code

Source: Internet
Author: User
Tags explode header php file php code php example socket strlen

Write a PHP weather thief ride

<?php
/***
Weather forecast
***/
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;
Todo
{
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= Hefei &zhou=yz";
$VaX 1tem=readall ($TQURL);
if (! $VaX 1Tem)
{
return false;
}
Settype ($ArrayTq, "array");
$ArrayTq =explode ("<!--weather forecast begins-->", $VaX 1Tem);
$ArrayTq =explode ("<!--weather forecast over-->", $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);
Weather
$ArrayTqTem 2=explode ("<tr><td>", $ArrayTq [0]);
$ArrayTqTem 2=explode ("</td></tr>", $ArrayTqTem 2[1]);
$ArrayTqTem 2=explode ("<td>", $ArrayTqTem 2[0]);
$ArrayTqTem 2= $ArrayTqTem 2[0];
Wind
$ArrayTqTem 3=explode ("<tr><td>", $ArrayTq [0]);
$ArrayTqTem 3=explode ("</td></tr>", $ArrayTqTem 3[2]);
$ArrayTqTem 3=explode ("<td>", $ArrayTqTem 3[0]);
$ArrayTqTem 3= $ArrayTqTem 3[0];
Temperature
$ArrayTqTem 4=explode ("<tr><td>", $ArrayTq [0]);
$ArrayTqTem 4=explode ("</td></tr>", $ArrayTqTem 4[3]);
$ArrayTqTem 4=explode ("<td>", $ArrayTqTem 4[0]);
$ArrayTqTem 4= $ArrayTqTem 4[0];
if (! $ArrayTqTem 2 or! $ArrayTqTem 3 or! $ArrayTqTem 4)
{
return false;
}
$TqVar = $ArrayTqTem 2. ",". $ArrayTqTem 3. " <br> temperature: ". $ArrayTqTem 4;
$weather [0]= $flash;
$weather [1]= $ArrayTqTem 2;
$weather [2]= $ArrayTqTem 3;
$weather [3]= $ArrayTqTem 4;
return $weather;
}
$weather = Get_weather ();
?>

It says PHP file, you don't have echo, of course it doesn't work.

<?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 ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Weather Forecast </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, XXFarEastFont-list-style:none;margin-top:3px; letter-spacing:1px;
</style>
<body>
<div>
<a href= "http://www.ttqx.com.cn/tqyb/" target= "_blank" ></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>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.