Home > Backend Development > PHP Tutorial > PHP unserialize出现Error at offset错误 mfc serialize serializable jquery serialize

PHP unserialize出现Error at offset错误 mfc serialize serializable jquery serialize

WBOY
Release: 2016-07-29 08:54:55
Original
1306 people have browsed it

  1. php
  2. //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";}
  3. //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";}
  4. 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(

  1. $string){return
  2. unserialize(
  3. 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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template