-
php
- //My page is UTF-8 encoded and the result is: a:2:{s:2:"en";s:21:"http:// www.phpddt.com";s:2:"cn";s:6:"Tutorial";}
- //My page is ANSI encoded and the result is: a:2:{s:2:" en";s:21:"http://www.phpddt.com";s:2:"cn";s:4:"tutorial";}
- echo serialize(array ('en'=>'http://www.phpddt.com','cn'=> It is easy to see from the above that the encoding of the page is different, and the length of the Chinese string serialized is different, and the problem arises. If the length of the string is greater than the actual string length when you unserialize, the following will be reported Error:
Notice: unserialize() [function.unserialize]: Error at offset
The solution is that you need to convert the deserialized string once:
function
_unserialize(
- $string){return
- unserialize(
- preg_replace( '!s:(d+):"(.*?) ";!se','"s:".strlen("$2").":"$2";"', $string));}
Reprinted from:
http://www.phpddt.com/php/unserialize-error-at-offset.html
The above introduces the Error at offset error in PHP unserialize, including the content of serialize. I hope it will be helpful to friends who are interested in PHP tutorials.