note 19127 modified in function.unserialize by john

From: Date: Wed, 20 Nov 2002 02:47:26 +0000
Subject: note 19127 modified in function.unserialize by john
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-39724@lists.php.net to get a copy of this message
Here you go, free to the world. My contribution to help deal with serialized data that contains backslashes. Add these two functions to your code: bs_shuffle(&$variable); function bs_shuffle($in) { $in=preg_replace('/\\/', '#BS#', $in); } function bs_unshuffle($in) { $in=preg_replace('/#BS#/', '\\', $in); } Now, your variables will have *no* backslashes in them when you serialize them. Run bs_shuffle(&$var) (don't forget the "&"), then serialize($var)... when you retrieve it later, you can bs_unshuffle(&$var) and it's back to its backslashed self. --was-- Ok, I'm an idiot... :) Here are the correct functions for shuffling backslashes; they should still be called with "&" in front of the variable passed to them; that is, bs_shuffle(&$variable); function bs_shuffle($in) { $in=preg_replace('/\\/', '#BS#', $in); } function bs_unshuffle($in) { $in=preg_replace('/#BS#/', '\\', $in); } http://www.php.net/manual/en/function.unserialize.php

« previous php.notes (#39724) next »