note 83997 deleted from function.unserialize by aharvey
| From: | aharvey@php.net | Date: | Tue, 06 Nov 2012 01:35:19 +0000 |
| Subject: | note 83997 deleted from function.unserialize by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191717@lists.php.net to get a copy of this message | ||
Note Submitter: pierre dot spring at liip dot ch
----
props to steve at bluearena dot com and getmequick at gmail dot com
when using the regex proposed by steve at bluearena dot com when working with serialized objects
that have been utf-8 encoded, i ran into a problem...
"\0" became 2 characters, instead of the zero ascii character.
the solution is pretty subtle:
<? php
# zero ascii "\0" becomes '\0'
$error = preg_replace('!s:(\d+):"(.*?)";!se',
"'s:'.strlen('$2').':\"$2\";'", $unserialized );
$works = preg_replace('!s:(\d+):"(.*?)";!se',
'"s:".strlen("$2").":\"$2\";"', $unserialized );
?>