Copy CodeThe code is as follows:
Nationwide, judging whether the $request_uri contains HTML
if (!strpos ($_server["Request_uri"], ". html"))
{
$page = "http://qq.ip138.com/weather/";
$html = file_get_contents ($page, ' R ');
$pattern = "/
National major cities, counties and the next five days of weather trend forecast online Query <\/B> (. *?) /si ";
The HTML between regular matches
Preg_match ($pattern, $html, $PG);
echo "";
Regular replace remote address to local address
$p =preg_replace ('/\/weather\/(\w+) \/index.htm/', ' tq.php/$1.html ', $PG [1]);
Echo $p;
}
Province, the judge condition is $request_uri whether contain?
else if (!strpos ($_server["Request_uri"], "?")) {
Yoyo recommends using split to get data, here is the name of the province to get
$province =explode ("/", $_server["Request_uri"]);
$province =explode (".", $province [Count ($province)-1]);
$province = $province [0];
I write my own regular notes, I feel bad, but the effect is equal to the above
Preg_match ('/[^\/]+[\. ( html)]$/', $_server["Request_uri"], $pro);
$province =preg_replace ('/\.html/', ', $pro [0]);
$page = "http://qq.ip138.com/weather/". $province. " /index.htm ";
Try to open the page before getting the HTML data to prevent a malicious input address from causing an error
if (! @fopen ($page, "R")) {
Die ("Sorry, this address does not exist! Click here to return");
Exit (0);
}
$html = file_get_contents ($page, ' R ');
$pattern = "/five-day weather trend Forecast <\/B> (. *?) Please input city/si ";
Preg_match ($pattern, $html, $PG);
echo "";
Regular replacement, get province, city
$p =preg_replace ('/\/weather\/(\w+) \ (\w+). htm/', ' $2.html?pro=$1 ', $PG [1]);
Echo $p;
}
else {
City, pass the province through get
$pro =$_request[' Pro '];
$city =explode ("/", $_server["Request_uri"]);
$city =explode (".", $city [Count ($city)-1]);
$city = $city [0];
Preg_match ('/[^\/]+[\. ( HTML)]+[\?] /', $_server["Request_uri"], $cit);
$city =preg_replace ('/\.html\?/', ', $cit [0]);
$page = "http://qq.ip138.com/weather/". $pro. " /". $city.". HTM ";
if (! @fopen ($page, "R")) {
Die ("Sorry, this address does not exist! Click here to return");
Exit (0);
}
$html = file_get_contents ($page, ' R ');
$pattern = "/five-day weather trend Forecast <\/B> (. *?) Please input city/si ";
Preg_match ($pattern, $html, $PG);
echo "";
Get the real picture address
$p =preg_replace ('/\/image\//', ' http://qq.ip138.com/image/', $PG [1]);
Echo $p;
}
?>
http://www.bkjia.com/PHPjc/321712.html www.bkjia.com true http://www.bkjia.com/PHPjc/321712.html techarticle Copy the code as follows: PHP//National, determine whether $request_uri contains HTML if (!strpos ($_server["Request_uri"], ". html")) {$page = "http:// Qq.ip138.com/weather/"; $html = ...