Home >Backend Development >PHP Tutorial >PHP compression function (gzcompress gzuncompress) compresses strings

PHP compression function (gzcompress gzuncompress) compresses strings

WBOY
WBOYOriginal
2016-07-25 08:54:481613browse
  1. //String compression example
  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); The compression rate of this operation can reach about 50%.
Copy code

In addition, the functions gzencode() and gzdecode() can achieve similar results by using different compression algorithms.



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