note 89816 deleted from function.unserialize by thiago
| From: | thiago@php.net | Date: | Tue, 24 Mar 2009 15:30:15 +0000 |
| Subject: | note 89816 deleted from function.unserialize by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-152392@lists.php.net to get a copy of this message | ||
Note Submitter: lightinthedark
----
@ chris at r3i dot it
I found that your code works for sorting out single quotes, but then fails on double quotes. I found
that this was a magic_quotes-related problem (frankly I think magic_quotes is a bad idea from the
outset, but that's a rant for another time and place). I got my code to work as desired by
using the following:
<?php
function mb_unserialize( $serial_str )
{
if( get_magic_quotes_gpc() || get_magic_quotes_runtime() ) {
$out = preg_replace('!s:(\d+):"(.*?)";!se',
"'s:'.strlen(stripslashes('$2')).':\"'.stripslashes('$2').'\";'",
$serial_str );
}
else {
$out = preg_replace('!s:(\d+):"(.*?)";!se',
"'s:'.strlen('$2').':\"$2\";'", $serial_str );
}
return unserialize($out);
}
?>
Hope it helps someone.