gzip files and string decompression instances tutorial

Source: Internet
Author: User

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);



Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.