转换序列化数据

时间:2015-11-07 11:40:15

标签: php arrays

如何将下面的序列化数据转换为数组格式?

a:11:{s:10:"session_id";s:32:"2605e956d2f16c07997af0516cdb65e7";s:10:"ip_address";s:12:"192.168.1.73";s:10:"user_agent";s:50:"Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (";s:13:"last_activity";s:10:"1446889396";s:8:"loggedin";s:0:"";s:5:"email";s:19:"admin@dgafhgdfh.com";s:7:"user_id";s:1:"1";s:8:"is_admin";s:1:"1";s:9:"signature";s:40:"c91bbb90da0958cad12c71d47003acbcf2df618e";s:18:"flash:old:redirect";s:33:"http://192.168.1.73:1052/openvbx/";s:18:"flash:new:redirect";s:33:"http://192.168.1.73:1052/openvbx/";}

提前谢谢。

1 个答案:

答案 0 :(得分:1)

该字符串是在数组上运行serialize()的结果。

要将其转换回数组,您需要在其上运行unserialize(),如下所示: -

$s = 'a:11:{s:10:"session_id";s:32:"2605e956d2f16c07997af0516cdb65e7";s:10:"ip_address";s:12:"192.168.1.73";s:10:"user_agent";s:50:"Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (";s:13:"last_activity";s:10:"1446889396";s:8:"loggedin";s:0:"";s:5:"email";s:19:"admin@dgafhgdfh.com";s:7:"user_id";s:1:"1";s:8:"is_admin";s:1:"1";s:9:"signature";s:40:"c91bbb90da0958cad12c71d47003acbcf2df618e";s:18:"flash:old:redirect";s:33:"http://192.168.1.73:1052/openvbx/";s:18:"flash:new:redirect";s:33:"http://192.168.1.73:1052/openvbx/";}';

$array = unserialize($s);

print_r($array);

结果是: -

Array
(
    [session_id] => 2605e956d2f16c07997af0516cdb65e7
    [ip_address] => 192.168.1.73
    [user_agent] => Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (
    [last_activity] => 1446889396
    [loggedin] =>
    [email] => admin@dgafhgdfh.com
    [user_id] => 1
    [is_admin] => 1
    [signature] => c91bbb90da0958cad12c71d47003acbcf2df618e
    [flash:old:redirect] => http://192.168.1.73:1052/openvbx/
    [flash:new:redirect] => http://192.168.1.73:1052/openvbx/
)