取消序列化PHP字符串
我有一个从我的函数之一返回的序列化字符串:取消序列化PHP字符串,php,arrays,Php,Arrays,我有一个从我的函数之一返回的序列化字符串: a:1:{i:0;a:3:{s:2:"id";s:24:"xxxxxxxxxxxxxxxxxxxxxxxx";s:11:"description";s:3:"Two";s:9:"users-idt";s:36:"x6543rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrd";}} 但是当我在上面使用unserialize时,它不会返回数组 <?php $arr = unserialize($string); //returns e
a:1:{i:0;a:3:{s:2:"id";s:24:"xxxxxxxxxxxxxxxxxxxxxxxx";s:11:"description";s:3:"Two";s:9:"users-idt";s:36:"x6543rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrd";}}
但是当我在上面使用unserialize时,它不会返回数组
<?php
$arr = unserialize($string); //returns empty
您的-最初发布的-序列化字符串无效,请参阅计算字符串len的结果:
<?php
$original = 'a:1:{i:0;a:3:{s:2:"id";s:24:"xxid";s:11:"description";s:3:"Two";s:9:"user-id";s:36:"x6543rd";}}';
|| || ||
\/ \/ \/
$edited = 'a:1:{i:0;a:3:{s:2:"id";s:4:"xxid";s:11:"description";s:3:"Two";s:7:"user-id";s:7:"x6543rd";}}';
$arr = unserialize($edited);
echo '<pre>';
var_dump($arr);
echo '</pre>';
?>
//output
array(1) {
[0]=>
array(3) {
["id"]=>
string(4) "xxid"
["description"]=>
string(3) "Two"
["user-id"]=>
string(7) "x6543rd"
}
}
序列化数据的内容无效。您是否更改了某些值?显示用于创建此字符串的代码。s:36:X6543不长36个字符同上s:24:XXID请参见编辑。字符串是有效的。但在运行数组时,似乎无法获得数组作为回报unserialize@LeanderIversen你真的觉得它像JSON吗?
array(1) {
[0]=>
array(3) {
["id"]=>
string(24) "xxxxxxxxxxxxxxxxxxxxxxxx"
["description"]=>
string(3) "Two"
["users-idt"]=>
string(36) "x6543rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrd"
}
}