本文介绍了在PHP中压缩字符串的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gzcompress压缩数组(json_encode($ arr),9)。
所以我使用json_encode将数组转换为字符串,然后使用gzcompress压缩。
但是我找不到结果字符串大小的很大差异。
压缩大小为488 KB之前,压缩大小为442 KB之后。



有没有办法进一步压缩字符串?



提前感谢。

解决方案

字符串的压缩效果取决于要压缩的数据。如果它主要由随机数据组成,你不会实现这么大的改进。有很多算法是为具体用途而设计的。



您应该尝试确定要压缩的数据主要包括,然后选择适当的压缩。 / p>

刚才我只能引荐您 bzcompress ,bzip的压缩率通常比gzip高。


I am compressing the array with gzcompress(json_encode($arr),9).So I am converting array into string with json_encode and then compress with gzcompress.But I could not find the much difference in the size of the resulted string.Before compression size is 488 KB and after compression size is 442 KB.

Is there any way I can compress the string further?

Thanks in advance.

解决方案

How good the compression of your string will be depends on the data you want to compress. If it consists mainly of random data you won't achieve that much improvements in size. There are many algorithms out there which have been designed for specific usage.

You should try to determine what your data to compress mainly consists of and then select a proper compression.

Just now I can only refer you to bzcompress, bzip has usually highter compression rates than gzip.

这篇关于在PHP中压缩字符串的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 00:38