Home > Article > Backend Development > php unserialize function error, very strange?
$test_str = "code|s:5:\"ZH9JC\";state|s:10:\"wn4rzbnxpp\";";
var_dump(unserialize($test_str));
This is the code, simple string, but still error. . .
$test_str = "code|s:5:\"ZH9JC\";state|s:10:\"wn4rzbnxpp\";";
var_dump(unserialize($test_str));
This is the code, simple string, but still error. . .
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