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

时间:2023年10月05日

/

来源:网络

/

编辑:佚名

::(滑稽) 当我们说到压缩,我们可能会想到文件压缩,其实,字符串也是可以压缩的。
PHP提供了 gzcompress() 和gzuncompress() 函数:
$string = “Lorem ipsum dolor sit amet, consectetur  adipiscing elit. Nunc ut elit id mi
ultricies  adipiscing. Nulla facilisi. Praesent pulvinar,  sapien vel feugiat vestibulum,
nulla dui pretium orci,  non ultricies elit lacus quis ante. Lorem ipsum dolor  sit amet,
consectetur adipiscing elit. Aliquam pretium ullamcorper urna quis iaculis. Etiam ac
massased turpis tempor luctus. Curabitur sed nibh eu elitmollis congue. Praesent ipsum diam,
consectetur vitae ornare a, aliquam a nunc. In id magna pellentesque tellus posuere
adipiscing. Sed non mi metus, at lacinia augue. Sed magna nisi, ornare in mollis in,
mollis sed nunc. Etiam at justo in leo congue mollis.Nullam in neque eget metus hendrerit
 scelerisque eu non enim. Ut malesuada lacus eu nulla bibendum  id euismod urna sodales. “;
/*压缩字符串*/
$compressed = gzcompress($string); 
echo “Original size: “. strlen($string).” ”; 
/* 输出原始大小 Original size: 800 */ 
echo “Compressed size: “. strlen($compressed).” ”;
 /* 输出压缩后的大小 Compressed size: 418 */ 
// 解压缩 
$original = gzuncompress($compressed);
猜你需要

豫ICP备2021026617号-1  豫公网安备:41172602000185   Copyright © 2021-2028 www.78moban.com/ All Rights Reserved

本站作品均来自互联网,转载目的在于传递更多信息,并不代表本站赞同其观点和对其真实性负责。如有侵犯您的版权,请联系 1565229909#qq.com(把#改成@),我们将立即处理。