PHP unzip the use of custom Gzdecode functions

Source: Internet
Author: User
In a microblogging project, the release video needs to parse out the chain to get the video address information,

Using the PHP curl to get the content, the regular parsing.

Later the test found that the potato video can not be resolved, the others are good.

After repeated testing, found that the potato with gzip compression, and then use Gzdecode anti-decompression.

Discover the local Wamp 2.1 zlib library, online cn.php.net search solution, Custom function Gzinflate implementation.

Here is the code

if (!function_exists (' Gzdecode ')) {    function Gzdecode ($data) {        $flags = Ord (substr ($data, 3, 1));        $headerlen = ten;        $extralen = 0;        $filenamelen = 0;        if ($flags & 4) {            $extralen = unpack (' V ', substr ($data, 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;    }}

Hope to be useful to everyone!

  • 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.