Home  >  Article  >  Backend Development  >  php unserialize function error, very strange?

php unserialize function error, very strange?

WBOY
WBOYOriginal
2016-09-11 11:34:161207browse

$test_str = "code|s:5:\"ZH9JC\";state|s:10:\"wn4rzbnxpp\";";
var_dump(unserialize($test_str));

This is the code, simple string, but still error. . .

php unserialize function error, very strange?

Reply content:

$test_str = "code|s:5:\"ZH9JC\";state|s:10:\"wn4rzbnxpp\";";
var_dump(unserialize($test_str));

This is the code, simple string, but still error. . .

php unserialize function error, very strange?

Is the serialized $test_str an array? Obviously not after serialization. If so, serialization is not like this, as follows:

$arr = array(
            'code' => 'ZH9JC',
            'state' => 'wn4rzbnxpp'
        );

$str = serialize($arr);
dump($str);
// string(59) "a:2:{s:4:"code";s:5:"ZH9JC";s:5:"state";s:10:"wn4rzbnxpp";}"
$content = unserialize($str);
dump($content);
//
array(2) {
  ["code"] => string(5) "ZH9JC"
  ["state"] => string(10) "wn4rzbnxpp"
}

Your string is not a standard serialized value. The unserialize function cannot recognize your character replacement, so it is wrong

$test_str is definitely the result of serialize?

This is not serialization...the format is wrong

It is not serialized, so it cannot be transferred

Statement:
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