微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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
@H_502_8@

这使我认为数据可能已被序列化两次.尽管经历了很多功能,例如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++;
}
@H_502_8@

但是,这不起作用.这与$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
@H_502_8@

结果如下:

string 'a:16:{s:2:"id";s:9:"123456";s:4:"name";s:12:"Henkie";s:10:"first_name";s:4: //and so on
@H_502_8@

从结果中可以看到,它只是从一开始就删除了“ s:668:”,这表明它是一个668字符串,其余部分保持不变.

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

解决方法:

您可以两次反序列化:

$unserialized = unserialize(unserialize($userMeta [‘facebookMeta’]));;

注意:使用update_user_Meta时无需序列化,它会自动为您序列化,请参阅. might_serialize:http://codex.wordpress.org/Function_Reference/maybe_serialize

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐