php 利用gzcompress()压缩数据入门实例

前端之家收集整理的这篇文章主要介绍了php 利用gzcompress()压缩数据入门实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:

/**
 * gzcompress()压缩数据
 *
 * @param 
 * @author 编程之家 jb51.cc jb51.cc
 **/
$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 massa
sed turpis tempor luctus. Curabitur sed nibh eu elit
mollis 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)."\n";
/* prints
Original size: 800
*/
echo "Compressed size: ". strlen($compressed)."\n";
/* prints
Compressed size: 418
*/
// getting it back
$original = gzuncompress($compressed);

猜你在找的PHP相关文章