php序列化数据无法反解析,PHP-反序列化数据不起作用

过去5个小时一直在这里工作,我很困惑.尝试了最荒谬的功能来尝试对其进行修复,但无济于事.

我正在从WP数据库中检索数据.在插入数据之前,已使用PHP的serialize()函数对1个数组进行了序列化.然后使用WP函数update_user_meta将其插入WP数据库. This function的参考资料说:

$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字符串,其余部分保持不变.

为什么反序列化无法正常工作?

解决方法:

您可以两次反序列化:

$unserialized = unserialize(unserialize($usermeta [‘facebookmeta’]));;

标签:php,wordpress,serialization

来源: https://codeday.me/bug/20191012/1897025.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值