note 35105 added to function.session-decode
| From: | redbeardATmdjohnsonDOTus at rack1 dot php dot net | Date: | Tue, 19 Aug 2003 20:27:54 +0000 |
| Subject: | note 35105 added to function.session-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-54714@lists.php.net to get a copy of this message | ||
I have a cleaner version of sess_string_to_array. Unfortunately, it chokes on multidimensional
arrays and strings that contain '";' (in arrays or by themselves). I also
haven't thouroughly tested it but it works (so far) for my purposes.
function serssion_unserialize($str)
{
$varRegex =
'(([a-zA-Z0-9_]+)' . // Var name
'\\|' . // separator
'((N;)|' . NULL
'(s:[0-9]+:".+";)|' . // Strings
'(a:[0-9]+:{((s:[0-9]+:".+";)|([a-rt-z]:[^;]*;))*})|' . // array
'([b-rt-z]:[^;]*;)))'; // Anything else (I hope)
$matches = array();
$data = array();
preg_match_all($varRegex, $str, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$data[$match[1]] = unserialize($match[2]);
}
return $data;
}
----
Manual Page -- http://www.php.net/manual/en/function.session-decode.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+35105
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+35105&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+35105&report=yes