过去 5 个小时我一直在做这个,我被难住了。尝试了最荒谬的功能来尝试修复它,但无济于事。
我正在从 WP 数据库检索数据。在插入之前,数据已使用以下方法序列化了 1 个数组:serialize()
来自 PHP 的函数。然后使用 WP 函数将其插入到 WP 数据库中update_user_meta
. 这个功能的参考文献说:
$meta_value
(mixed) (required) The new desired value of the meta_key, which must be different from the
existing value. Arrays and objects will be automatically serialized.
Note that using objects may cause this bug to popup.
Default: None
这让我觉得数据可能被序列化了两次。尽管经历了很多功能,例如unserialize()
, array_map
, json_decode
,以及这些和更多的组合,我现在得到了以下内容:
$i = 0;
while($i < count($fbData)){
$someValue = $fbData[$i]['meta_value'];
$usermeta = array_map( function( $a ){ return $a[0]; }, get_user_meta( $fbData[$i]['user_id'] ));
if( $usermeta['facebookmeta'] ){
$unserialized = unserialize( $usermeta['facebookmeta'] );
//other methods tried: unserialize( unserialize
// unserialize( json_decode(
// json_decode( unserialize( json_decode(
// json_decode( unserialize(
// unserialize( array_map(
// unserialize( array_map( json_decode
// whole lot others
var_dump( $unserialized );
}
$i++;
}
然而这不起作用。这与$fbData
:
'facebookmeta' => string 's:668:"a:16:{s:2:"id";s:9:"123456";s:4:"name";s:12:"Henkie";s:10:"first_name";s:4 //and so on
这是结果:
string 'a:16:{s:2:"id";s:9:"123456";s:4:"name";s:12:"Henkie";s:10:"first_name";s:4: //and so on
从结果中可以看出,它只是删除了“s:668:"
" 从一开始,这表明它是一个 668 个字符的字符串,其余部分保持不变。
为什么反序列化不能正常工作?