PHP file_get_contents function to easily capture ip138 data

Source: Internet
Author: User

<?php Tutorial
Nationally, the criterion is whether $request_uri contains HTML
if (!strpos ($_server["Request_uri"], ". html"))
{
$page = "http://qq.ip138.com/weather/";
$html = file_get_contents ($page, ' R ');
$pattern = "/<b> National main cities, counties and the next five days of weather trend forecast online Inquiry </B> (. *?) <center style= "padding:3px" >/si ";
The HTML between regular matches
Preg_match ($pattern, $html, $PG);
echo "";
Regular replace remote address as local address
$p =preg_replace ('//weather/(w+)/index.htm/', ' tq.php/$1.html ', $PG [1]);
Echo $p;
}
Province, the judge condition is whether $request_uri contains?
else if (!strpos ($_server["Request_uri"], "?")) {
Yoyo recommended using segmentation to get data here is the name of the province
$province =explode ("/", $_server["Request_uri"]);
$province =explode (".", $province [Count ($province)-1]);
$province = $province [0];
Be commented out is my own writing out of the regular, feel bad writing, 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 the malicious input address from causing an error
if (! @fopen ($page, "R")) {
Die ("Sorry, the address does not exist!<a Href=javascript Tutorial: History.back (1) > Click here to return </a>");
Exit (0);
}
$html = file_get_contents ($page, ' R ');
$pattern = "/Five Weather trend Forecast </B> (. *?) Please input the city/si ";
Preg_match ($pattern, $html, $PG);
echo "";
Regular substitution, acquisition of provinces, cities
$p =preg_replace ('//weather/(w+)/(w+). htm/', ' $2.html?pro=$1 ', $PG [1]);
Echo $p;
}
else {
City, passing the provinces 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, the address does not exist!<a Href=javascript:history.back (1) > Click here to return </a>");
Exit (0);
}
$html = file_get_contents ($page, ' R ');
$pattern = "/Five Weather trend Forecast </B> (. *?) Please input the 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;
}
?>

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.