The following php code compresses and decompresses strings through gzcompress and gzuncompress. The compression level can be set
- $str = 'Hello I am a very very very long string';
- $compressed = gzcompress($str, 9 );//The compression level is 9
- $uncompressed = gzuncompress($compressed);
-
- echo $str, "n";
- echo $uncompressed, "n";
- echo base64_encode($compressed), "n";
- echo bin2hex($compressed), "n";
- echo urlencode($compressed), "n";
Copy code
|