For details about how to decompress the gzip file or string in php, refer to _ PHP
Source: Internet
Author: User
To collect a website, the target site uses gzip to compress and transfer the webpage. you should have to send an http header Accept-Encoding: identity or simply not send this header, the target site can return a page that has not been compressed by gzip, but unfortunately, the target site ignores the fact that php is very easy to decompress gzip, and you can use the built-in gzdecode function, unfortunately, after being configured for half a day, I cannot support the gzdecode function:
The code is as follows:
If (! Function_exists ('gzdemo ')){
Function gzdecode ($ data ){
$ Flags = ord (substr ($ data, 3, 1 ));
$ Headerlen = 10;
$ Extralen = 0;
$ Filenamelen = 0;
If ($ flags & 4 ){
$ Extralen = unpack ('v', substr ($ data, 10, 2 ));
$ Extralen = $ extralen [1];
$ Headerlen + = 2 + $ extralen;
}
If ($ flags & 8) // Filename
$ Headerlen = strpos ($ data, chr (0), $ headerlen) + 1;
If ($ flags & 16) // Comment
$ Headerlen = strpos ($ data, chr (0), $ headerlen) + 1;
If ($ flags & 2) // CRC at end of file
$ Headerlen + = 2;
$ Unpacked = @ gzinflate (substr ($ data, $ headerlen ));
If ($ unpacked = FALSE)
$ Unpacked = $ data;
Return $ unpacked;
}
}
The call method is simple:
The code is as follows:
$ F = @ file_get_contents ("http://www.bitsCN.com ");
Echo gzdecode ($ f );
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.