我不能在任何地方找到的東西來處理序列化的字符串,它不是我見過的該格式。
然而,繼承人快速功能,把它變成一個數組(它可能不是太優雅,但我只有1種咖啡):
$string = 'active|i:1487613760;user_username|s:20:"[email protected]";user_key|s:8:"a5186adc";authenticated|b:1;user_name|s:12:"victor";user_email|s:20:"[email protected]";remember|b:1;
';
$array = deserializeSessionString($string);
echo $array['user_key'];
// deserialize a session string into an array
function deserializeSessionString($string)
{
$output = [];
// separate the key-value pairs and iterate
foreach(explode(';', $string) as $p) {
// separate the identifier with the contents
$bits = explode('|', $p);
// conditionally store in the correct format.
if(isset($bits[1])) {
$test = explode(':', $bits[1]);
switch($test[0]) {
// int
case 'i':
$output[$bits[0]] = $test[1];
break;
case 's':
// string
// ignore test[1], we dont care about it
$output[$bits[0]] = $test[2];
break;
case 'b':
// boolean
$output[$bits[0]] = ($test[1] == 1 ? true : false);
break;
}
}
}
return $output;
}
,那麼你應該能夠訪問你需要只用鑰匙:
echo $array['user_key'];
heres an example
,似乎一個奇怪的序列化格式,如何您的會話處理程序序列化呢? – DevDonkey