To collect a website, the target station adopted gzip compressed transmission page, should have sent an HTTP header accept-encoding:identity or simply do not send this first class, you can make the target station returned without gzip compressed pages, but unfortunately, The target station ignores client requests and still returns gzip data, resulting in garbled characters.
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:
|
The following are the referenced contents:
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:
|
The following are the referenced contents:
$f = @file_get_contents ("http://www.itlearner.com");
echo Gzdecode ($f); |