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 () and base64_decode