note 101160 added to function.session-decode

From: Date: Tue, 30 Nov 2010 14:59:00 +0000
Subject: note 101160 added to function.session-decode
Groups: php.notes 
Request: Send a blank email to php-notes+get-174471@lists.php.net to get a copy of this message
My go at unserializing the session values: 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; } ---- Server IP: 69.147.83.197 Probable Submitter: 194.78.141.42 ---- Manual Page -- http://www.php.net/manual/en/function.session-decode.php Edit -- https://master.php.net/note/edit/101160 Del: integrated -- https://master.php.net/note/delete/101160/integrated Del: useless -- https://master.php.net/note/delete/101160/useless Del: bad code -- https://master.php.net/note/delete/101160/bad+code Del: spam -- https://master.php.net/note/delete/101160/spam Del: non-english -- https://master.php.net/note/delete/101160/non-english Del: in docs -- https://master.php.net/note/delete/101160/in+docs Del: other reasons-- https://master.php.net/note/delete/101160 Reject -- https://master.php.net/note/reject/101160 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174471) next »