There may be several reasons for this error. The answer to the online search is basically targeted. The key is how to find the cause and solve it. Analysis 1: In the data storage and deserialization encoding problem error this cause is very common, for example, originally stored in GBK encoding, then UTF-8 encoding, then in the uns
There may be several reasons for this error. The answer to the online search is basically targeted. The key is how to find the cause and solve it. Analysis 1: In the data storage and deserialization encoding problem error this cause is very common, for example, originally stored in GBK encoding, then UTF-8 encoding, then in the uns
There may be several reasons for this error. The answer to the online search is basically targeted. The key is how to find the cause and solve it.
Analysis 1: Encoding Error during data storage and deserialization
This is very common, for example, originally stored in GBK encoding, and then UTF-8 encoding, then in the unserialize () There will be a problem;
Solution 1: Convert the data of UTF-8 encoding into GBK, PHP can use iconv () function;
Analysis 2: rewrite Reverse Sequence Functions
In some cases, you can rewrite the underlying function and convert gb2312 to UTF-8 format, the number of bytes per Chinese character increases from 2 to 3, leading to a problem in determining the character length during deserialization, therefore, you need to use a regular expression to re-calculate the character Length Value in the serialized array. The Code is as follows:
function
mb_unserialize(
$serial_str
) {
? ? $out
= preg_replace(
'!s:(\d+):"(.*?)";!se'
,
"'s:'.strlen('$2').':\"$2\";'"
,
$serial_str
);
? ? return
unserialize(
$out
);
}
Solution 3: Perform base64_encode on the character data, and then serialize serialization. During restoration and extraction, unserialize () is followed by base64_decode.
Original article address: Notice: unserialize () [function. unserialize]: Error. Thank you for sharing it.