unserialize() [function.unserialize]: Error at offset

$a = 'a:1:{i:0;s:12:"1,10,93,";}';
var_dump( unserialize( $a ) );

  运行之后页面上显示Notice: unserialize(): Error at offset 11 of 26 bytes in H:\wamp\www\test\test.php on line 8( 注意:在11 unserialize()偏移26字节的错误 )

 

解决方法:使用正则表达式将序列化的数组中的表示字符长度的值重新计算一遍

$a = 'a:1:{i:0;s:12:"1,10,93,";}';
$data = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $a);
var_dump( unserialize( $data ) );

运行的结果就显示正确了  array(1) { [0]=> string(8) "1,10,93," }

 

参考:http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset

posted @ 2015-08-14 14:45  贱书生  阅读(604)  评论(0编辑  收藏  举报