note 19054 deleted from function.unserialize by john
| From: | john@php.net | Date: | Wed, 20 Nov 2002 02:46:45 +0000 |
| Subject: | note 19054 deleted from function.unserialize by john | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-39723@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:
function bs_shuffle(&$in) {
// The Backslash Shuffle, as I like to call it.
preg_replace('/\\/', '#BS#', &$in);
}
function bs_unshuffle(&$in) {
// ...and the corresponding Unshuffle.
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.