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.
serialize
And
json_encode
,
serialize
Ratio
json_encode
The length of the string to be converted must be less than 1/3.
PHP
There is nothing else
FunctionOr
MethodCan be converted
String with less Length?
Reply content:
Because I tried to save the array information to the database.serialize
Andjson_encode
,serialize
Ratiojson_encode
The length of the string to be converted must be less than 1/3.PHP
There 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.