欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php压缩和解压缩字符串的代码

程序员文章站 2022-05-12 17:33:15
...

下面php代码通过gzcompress和gzuncompress压缩和解压缩字符串,可以设定压缩级别

  1. $str = 'Hello I am a very very very very long string';
  2. $compressed = gzcompress($str, 9);//压缩级别为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";
复制代码

php