Php reads the remote gzip compressed webpage and php reads the gzip compressed webpage. Php reads the remote gzip compressed webpage. When php reads the gzip compressed webpage information of a mall today, it uses file_get_contents or curl: The copy code is as follows: $ u php reads the remote gzip compression webpage, and php reads the gzip compression
When retrieving the page information of a mall today, use file_get_contents or curl:
The code is as follows:
$ Url = 'http: // www.xxx.com/21 /? Type = 23 ′;
$ Temp = file_get_contents ($ url );
Echo $ temp;
All of the results are garbled. I checked a lot of content, including the header information of the page, and found that the original page was used.
Similar information, that is, the Content-Encoding is gzip, that is, the site has enabled gzip compression. There are many solutions here. of course, if you use file_get_contents, you can modify it as follows:
The code is as follows:
File_get_contents ("compress. zlib: //". $ url );
Or use curl to complete:
The code is as follows:
Function curl_get ($ url, $ gzip = false ){
$ Curl = curl_init ($ url );
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ curl, CURLOPT_CONNECTTIMEOUT, 10 );
If ($ gzip) curl_setopt ($ curl, CURLOPT_ENCODING, "gzip"); // The key here
$ Content = curl_exec ($ curl );
Curl_close ($ curl );
Return $ content;
}
At the same time, refer to the above solution in the manual, you can also save the gzip string for processing as follows:
The code is as follows:
Function gzdecode ($ data ){
$ G = tempnam ('/tmp', 'FF ');
@ File_put_contents ($ g, $ data );
Ob_start ();
Readgzfile ($ g );
$ D = ob_get_clean ();
Return $ d;
}
When retrieve the page information of a mall today, use file_get_contents or curl: the code is as follows: $ u...