views:

51

answers:

3

Any Php Class To Decode/Incode Strings with Gzip, compress, x-gzip or x-compress Algorithm .

Thanks

+1  A: 

See in the manual: PHP: Compression and Archive functions

and there specifically: ZLib functions, e.g. gzcompress()

They require the ZLib module to be present.

Pekka
Thanks Pekka, but i needed a class that deals with all these algorithms, something like: decode($string,"x-gzip");
David
@David I see. I doubt there is going to be such a universal library. It would have to be a compiled extension, a PHP implementation of these would probably be awfully slow... Maybe you can put something together yourself but I don't know whether those other algorithms (what is `compress`?) have a PHP implementation at all. Anyway, just wait - maybe something comes up.
Pekka
+1  A: 

zlib - http://php.net/manual/en/book.zlib.php

fseto
A: 

If you just need a generic wrapper to decode based on a given method name, use an array instead:

 $decode = array(
     "gzip" => "gzdecode",
     "deflate" => "gzinflate",
     "compress" => "gzuncompress",
     "x-gzip" => "gzdecode",
     "x-deflate" => "gzinflate",
     "x-compress" => "gzuncompress",
 );

Then instead of decode($bin, "x-gzip") you just use:

 $uncompressed = $decode["x-gzip"]($bin_data);

Though I wonder about the use case. And maybe you'll better wrap it in a function.. :}

mario