Use serialize() to serialize the data and insert it into the database, and then use unserialize() to deserialize it and encounter some data string errors;
The error content is:unserialize() [function.unserialize ]: Error at offset 0 of 2544 bytes
I searched many solutions on Google and they all said that the problem was caused by encoding problems
So the place where I inserted it was changed to base64_encode(serialize($str));
The place where I read it was changed to
unserialize(preg_replace('!s:(d+):"(.*?)";!se', '"s:".strlen("$2").":"$2";"', $string))
I tried it and it worked but it was not completely resolved. Later, the same error occurred in some datagrams. Looking at the background data, I found that the inserted content turned into something similar to the garbled code below
< /p>
Please help me find out the reason, preferably in more detail.
Post some source data, otherwise how can you test it? .
Confirm whether there is any problem with your serialized data. I used serialize before, but it always had problems. Then I had no choice but to change to json_decode
base64_encode("a:1") == "YTox"
.That data is base64 encoded, not garbled.