note 6060 deleted from function.unserialize by sniper

From: Date: Mon, 13 Oct 2003 03:20:52 +0000
Subject: note 6060 deleted from function.unserialize by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58499@lists.php.net to get a copy of this message
Note Submitter: hans@virginia.edu ---- The problem I was concerned with was one where an array of query strings (i.e. form elements that had slashes automatically added) was being serialized. In that case, unserialize(stripslashes($myarray)) would not work, because it had been serialized with the slashes in the array elements (and therefore the element length info in the serialized data includes the slashes). One has to remove the slashes *from each array element* before serializing it. So: <PRE> function stripEach(&$element) { $element = stripslashes($element); } array_walk($myarray, "stripEach"); $serializedarray = serialize($myarray); # now addslashes() / stripslashes() can be safely # aplied to $serializedarray </PRE>

« previous php.notes (#58499) next »