php - 反序列化报错,后台数据变成疑似乱码?
phpcn_u1582
phpcn_u1582 2017-05-16 13:08:00
0
4
798

用serialize()序列化数据后插入数据库,再用unserialize()反序列化出来的时候遇到了部分数据字符串报错;
报错内容为:unserialize() [function.unserialize]: Error at offset 0 of 2544 bytes

谷歌搜了好多解决方法都是说用 是由于编码的问题导致的
于是在插入的地方改为 base64_encode(serialize($str));
读取的地方改为
unserialize(preg_replace('!s:(d+):"(.*?)";!se', '"s:".strlen("$2").":"$2";"', $string))

我就试了是有效但没有完全解决,后来还是出现部分数据报同样错误,查看后台数据可发现插入的内容变成了下图的类似乱码的东西

求各路大神帮忙看看什么原因,最好能详细点。

phpcn_u1582
phpcn_u1582

reply all(4)
PHPzhong

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.

刘奇
unserialize(base64_decode($str))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!