In fact, PHP to gzip decompression is very simple, with the built-in Gzdecode function on it, but unfortunately I have configured a half-day can not support the Gzdecode function, so have to modify:
Copy Code code as follows:
if (!function_exists (' Gzdecode ')) {
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 &)//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;
}
}
Calling the method is simple:
Copy Code code as follows:
$f = @file_get_contents ("http://www.jb51.net");
echo Gzdecode ($f);