开发者

Best way to compact a string in PHP that can be decoded to its original form

开发者 https://www.devze.com 2023-03-21 15:40 出处:网络
What would be the best way to compact a string in PHP that can be decoded to its original form. The base64_encode works for numbers but it yields 开发者_如何学运维a longer result for strings that cont

What would be the best way to compact a string in PHP that can be decoded to its original form. The base64_encode works for numbers but it yields 开发者_如何学运维a longer result for strings that contain special characters.


Gzencode and gzdecode use the GZIP compression algorithm and are very efficient on plain text strings. Just be aware that the output may (will) contain binary characters not suitable for display and possibly not suitable for database storage either.

(Edit: singe gzdecode doesn't ship with PHP, consider gzdeflate and gzinflate. Gzdeflate compresses a string and gzinflate decompresses it.)


Take your pick: Compression and Archive Extensions


well of course a base64-encoding makes a string longer as it is mapping all possible bytes onto a smaller set of numbers and alphabetic chars.

I guess convert_uuencode wouldn't increase the size of your binary string as much as base64 b/c the target set is larger.

0

精彩评论

暂无评论...
验证码 换一张
取 消