2015-11-07 81 views
-1

如何將序列化數據轉換爲數組格式?轉換序列化數據

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:"[email protected]";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/";} 

在此先感謝您。

+2

'反序列化()' –

回答

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:"[email protected]";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] => [email protected] 
    [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/ 
)