New here? Read Greetings Earthling!

A Better PHP GZDecode Function

As most of you know I had a very popular GZDecode version on my old blog. But, it was not really as good as it looked like. I found the problems when I was trying to expand a monthly GZEncoded raw access log. I realized it was a file made of many welded GZEncoded entities each on its own. So my way of expanding did not work.

I rewrote the algo for C++ by gzdecoding from end to beggining, but I was too lazy to do this in PHP so I made a new version to handle combined GZEncoded parts by using temporary files and using the gz* functions: gzopen, gzread.

So I'm sharing here both functions. The one that works in memory and handles one GZEncode entry data and the one that uses temporary files that can GZDecode anything GZEncoded :).

Old GZDecode Function

This is the old one that works well in 99% of the situations where you just need to gzdecode something. It can [optionally] return filename and comment if any exists.

Zone unavailable to unregistered users.
Registration is quick, painless and worth its weight in gold.

New GZDecode2File And GZDecode2Mem Functions

Uses GZRead to GZDecode any GZEncoded entity, including combined GZEncoded raw access logs.

Zone unavailable to unregistered users.
Registration is quick, painless and worth its weight in gold.

Have fun ... what can I say?

Category: PHP
Tagged: , , ,

7 Responses

  1. +m0Fo1:1 — #145 says:

    sys_get_temp_dir()

    Unknown function

  2. +Gary1:2 — #70 says:

    I registered and did not receive a password

    • And I’m not going to help you.
      I never help those who assign my emails to their ’special’ garbage folder.
      Cheers.

      • +Gary2:2 — #70 says:

        You mean you browse the web and provide random websites with your everyday work email address? I don’t know your site from some spam headquarters, and I can get in trouble if you start blasting my personal email address.

        I initially signed up with my personal hotmail account for what its worth. I didn’t know your blog sign-up process came with ’strings’ attached.

        • I’ve fixed the registration process but I nevertheless dislike email that contain spam or trash inside them.
          It’s like telling someone upfront that ou need to use him one time only and throw him to garbage afterwards.
          Not cool and it’s not about strings attached. It’s about decency and appearance.

          Be nice to people … even if you lie them.

          PS: Please register again.

  3. +pjoter1:1 — #199 says:

    Hi php developers,
    Iam trying to find solution to this problem for about 3 months. I have db file from cd catalog of car parts in sqlite3. I figure out whole db structure but i have problem with main table Strings. There are all strings from catalog but I think they are compressed or encoded (table structure KeyID and Language where Language are those strings). It should be decodable (so there should not be any pass or key) because I found many eshops working with same database, but they seems to be run on .NET. So i tryied pass the strings to functions gzinflate(), gzuncompress() with warning wrong data. Function gzdecode() doesnt exists so far. And now Iam trapped. Here is sample of one Language string:

    1. 0EB22F125D5F430A333E0810716545717A0B03

    Please anyone got idea how to uncompress/decode this string with PHP ?
    Any advices would be very welcomed