PHP中Notice: unserialize(): Error at offset of bytes in on line 的解决方法
2017-04-25 14:05
926 查看
使用unserialize函数将数据储存到数据库的时候遇到了这个报错,后来发现是将gb2312转换成utf-8格式之后,每个中文的字节数从2个增加到3个之后导致了反序列化的时候判断字符长度出现了问题,所以需要使用正则表达式将序列化的数组中的表示字符长度的值重新计算一遍,代码如下:
function mb_unserialize($serial_str) { $out = preg_replace_callback( '!s:(\d+):"(.*?)";!s', function($r){ return 's:'.strlen($r[2]).':"'.$r[2].'";'; }, $serial_str ); return unserialize($out); }
相关文章推荐
- [php错误]PHP中Notice: unserialize(): Error at offset of bytes in on line 的解决方法
- [php错误]PHP中Notice: unserialize(): Error at offset of bytes in on line 的解决方法
- PHP中Notice: unserialize(): Error at offset 109 of 615 bytes in on line 的解决方法
- Notice: unserialize(): Error at offset 134526789 of 2136547489 bytes in file.php on line 130
- unserialize(): Error at offset 0 of 96 bytes出现的原因分析以及解决方法
- PHP运行错最有效解决办法Fatal error: Out of memory (allocated 786432) (tried to allocate 98304 bytes) in H:\freehost\zhengbao2\web\includes\lib_common.php on line 744
- Notice: Undefined offset: 4 in d:\...\chaxun\rbora.php on line 96错误方法
- PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
- Notice: unserialize() [function.unserialize]: Error at offset解决方法
- PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
- Parse error: syntax error, unexpected end of file in *.php on line * 解决方法
- PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
- PHP出现Notice: unserialize() [function.unserialize]: Error at offset问题的解决方案
- PHP出现Notice: unserialize() [function.unserialize]: Error at offset问题的解决方案
- PHP出现Notice: unserialize() [function.unserialize]: Error at offset问题的解决方案
- 如何解决 Notice: Undefined index: submit in D:\wamp\www\bbs\add.php on line 9
- Fatal error: Call to undefined function Think\C() in /var/www/html/ceshi.hzheee.com/think/ThinkPHP/Library/Think/Think.class.php on line 334 这个问题解决
- Notice: Use of undefined constant out - assumed 'out' in D:wampwwwdaoruindex.php on line 4解决办法
- PHP webservice错误:XML error parsing SOAP payload on line 1解决方法
- PHP出现Notice: unserialize() [function.unserialize]: Error at offset问题的解决方案