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