In fact, it is very easy for php to decompress gzip. You can use the built-in gzdecode function, but it is a pity that I have been configured for half a day and cannot support the gzdecode function, so I have to work around it:
Copy codeThe 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:
Copy codeThe Code is as follows:
$ F = @ file_get_contents ("http://www.jb51.net ");
Echo gzdecode ($ f );