Is there a better way or function to convert an array into a string for storage (the smaller the string length, the better )?

Source: Internet
Author: User
Because I want to save the array information to the database, I tried to use serialize and json_encode. serialize has 13 less string lengths than json_encode conversion, but would you like to ask if there are other functions or methods in PHP that can be used to convert strings with less length? Because I tried to save the array information to the database. serializeAnd json_encode, serializeRatio json_encodeThe length of the string to be converted must be less than 1/3. PHPThere is nothing else FunctionOr MethodCan be converted String with less Length?

Reply content:

Because I tried to save the array information to the database.serializeAndjson_encode,serializeRatiojson_encodeThe length of the string to be converted must be less than 1/3.PHPThere is nothing elseFunctionOrMethodCan be convertedString with less Length?

No, json_encode is actually quite good, especially when the data may be directly called by the front-end. If your database space is insufficient, you can buy a hard disk. This is the best advice.
The more compression you compress, the more computation is required. It is more troublesome to decompress the compress, saving space and losing performance.

You can search for character string compression algorithms, such as http://www.jb51.net/article/46144.htm.

In general, unless otherwise specified, the CPU time is usually much higher than the disk space, so you do not need to waste CPU time for the disk space.
It is not worthwhile to compress and decompress strings.

It mainly depends on the requirement. What content is used after your string is compressed? If it is used to communicate with other parts, json is a better implementation method. If it is used for storage, forget it.

Implode (separator, array)

MessagePack is an efficient binary serialization format. It allows you to exchange data between different languages like JSON. But it is faster and smaller than JSON.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.