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

php压缩函数(gzcompress gzuncompress)压缩字符串

程序员文章站 2022-04-29 13:27:02
...
  1. //字符串压缩举例
  2. $string =
  3. “http://bbs.it-home.org is php technical website.This website is personal website.php8848.com has many php and mysql or other IT knowledage articles,so welcome to php8848.com!please enjoy it! it’s our honor if php8848 can help you !”;
  4. $compressed = gzcompress($string);
  5. echo “Original size: “. strlen($string).”n”;
  6. /* prints
  7. Original size: 800
  8. */
  9. echo “Compressed size: “. strlen($compressed).”n”;
  10. /* prints
  11. Compressed size: 418
  12. */
  13. // getting it back
  14. $original = gzuncompress($compressed);这种操作的压缩率能达到 50% 左右。
复制代码

另外,函数 gzencode() 和 gzdecode() 能达到类似结果,通过使用不同的压缩算法。