note 101427 deleted from function.session-decode by danbrown

From: Date: Thu, 16 Dec 2010 11:14:15 +0000
Subject: note 101427 deleted from function.session-decode by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174976@lists.php.net to get a copy of this message
Note Submitter: davyvandenbremt at gmail dot com ---- Here's what we are using to unserialize the session. <?php function unserialize_session($val) { $result = array(); // prefixing with semicolon to make it easier to write the regular expression $val = ';' . $val; // regularexpression to find the keys $keyreg = '/;([^|{}"]+)\|/'; // find all keys $matches = array(); preg_match_all($keyreg, $val, $matches); // only go further if we found some keys if (isset($matches[1])) { $keys = $matches[1]; // find the values by splitting the input on the key regular expression $values = preg_split($keyreg, $val); // unshift the first value since it's always empty (due to our semicolon prefix) if (count($values) > 1) { array_shift($values); } // combine the $keys and $values $result = array_combine($keys, $values); } return $result; } ?>

« previous php.notes (#174976) next »