Home >Backend Development >PHP Tutorial >PHP code to compress and decompress strings

PHP code to compress and decompress strings

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 08:44:171097browse

The following php code compresses and decompresses strings through gzcompress and gzuncompress. The compression level can be set

  1. $str = 'Hello I am a very very very long string';
  2. $compressed = gzcompress($str, 9 );//The compression level is 9
  3. $uncompressed = gzuncompress($compressed);
  4. echo $str, "n";
  5. echo $uncompressed, "n";
  6. echo base64_encode($compressed), "n";
  7. echo bin2hex($compressed), "n";
  8. echo urlencode($compressed), "n";
Copy code

php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn