In fact, php is very simple to decompress gzip. You can just use the built-in gzdecode function. However, unfortunately, I configured it for a long time and could not support the gzdecode function, so I had to work around it:
Copy code The code is as follows:
if (!function_exists('gzdecode')) { , 3, 1)); 4) { 'v' ,substr($data, 10, 2));
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 calling method is very simple:
Copy code
The code is as follows:
$f=@file_get_contents("http:/ /www.jb51.net");
echo gzdecode($f);
http://www.bkjia.com/PHPjc/319369.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/319369.html
TechArticle
In fact, PHP is very simple to decompress gzip, just use the built-in gzdecode function, but unfortunately it took me a long time to configure it It also cannot support the gzdecode function, so I have to work around it: Copy the code...