Notice: unserialize () [function. unserialize]: Error

Source: Internet
Author: User
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.

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.