1. $string =
  2. “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 !”;
  3. $compressed = gzcompress($string);
  4. echo “Original size: “. strlen($string).”n”;
  5. /* prints
  6. Original size: 800
  7. */
  8. echo “Compressed size: “. strlen($compressed).”n”;
  9. /* prints
  10. Compressed size: 418
  11. */
  12. // getting it back
  13. $original = gzuncompress($compressed);这种操作的压缩率能达到 50% 左右。
复制代码

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



09-18 23:38