The following gzip is a page I collected:
If you know the reason, we can do it. Baidu first finds that you can use curl instead.
Curl solution
| The code is as follows: |
Copy code |
|
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;
} |
Use gzip encoding format
File_get_contents solution:
| The code is as follows: |
Copy code |
|
File_get_contents ("compress. zlib: //". $ url ); |
The above code works normally regardless of whether the page is compressed by gzip!
Note: CURL must be enabled.
Curl installation:
Installation Under xp
: Modify the settings of the php. Ini file and find
| The code is as follows: |
Copy code |
| Php_curl.dll |
// Cancel the comment extension = php_curl.dll
Install it in linux:
| The code is as follows: |
Copy code |
|
# Wget http://curl.haxx.se/download/curl-7.17.1.tar.gz
# Tar zxvf curl-7.17.1.tar.gz // Unzip
# Cdcurl-7.17.1
#./Configure-prefix =/usr/local/curl
# Make
# Make install |
This is the method installed before installing php.