Ec (2); & lt ;? The php tutorial is nationwide and the condition is: $ REQUEST_URI contains htmlif (! Tags & quot;) {$ page & quot; qq. ip138.comweather & quot; $ htmlfile_get_contents (script ec (2); script
// The country determines if $ REQUEST_URI contains html
If (! Strpos ($ _ SERVER ["REQUEST_URI"], ". html "))
{
$ Page = "http://qq.ip138.com/weather ";
$ Html = file_get_contents ($ page, 'R ');
$ Pattern = "/Online query of weather trend forecasts for major cities, counties, and the next five days(.*?)
/Si ";
// Html between regular expression matching
Preg_match ($ pattern, $ html, $ pg );
Echo "";
// Replace the remote address with the local address
$ P = preg_replace ('// weather/(w +)/index.htm/', 'tq. php/$1.html ', $ pg [1]);
Echo $ p;
}
// Save. Check whether the condition is $ REQUEST_URI?
Else if (! Strpos ($ _ SERVER ["REQUEST_URI"], "? ")){
// Use the separation method recommended by yoyo to obtain data. Here, the province name is obtained.
$ Province = explode ("/", $ _ SERVER ["REQUEST_URI"]);
$ Province = explode (".", $ province [count ($ province)-1]);
$ Province = $ province [0];
// The comment is the regular expression written by myself. It is not easy to write, but the effect is equivalent to the above.
// Preg_match ('/[^/] + [. (html)] $/', $ _ SERVER ["REQUEST_URI"], $ pro );
// Define province1_preg_replace('.html/', '', $ pro [0]);
$ Page = "http://qq.ip138.com/weather/". $ province. "/index.htm ";
// Try to open the page before obtaining html data to prevent error caused by malicious address input
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(.*?) Enter city/si ";
Preg_match ($ pattern, $ html, $ pg );
Echo "";
// Obtain the province and city for regular expression replacement.
$ 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 );
// $Cityuncpreg_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(.*?) Enter city/si ";
Preg_match ($ pattern, $ html, $ pg );
Echo "";
// Obtain the real image address
$ P = preg_replace ('// image //', 'HTTP: // qq.ip138.com/image/', $ pg [1]);
Echo $ p;
}
?>