note 93606 modified in function.unserialize by thiago
| From: | thiago@php.net | Date: | Wed, 04 May 2011 03:31:52 +0000 |
| Subject: | note 93606 modified in function.unserialize by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-179396@lists.php.net to get a copy of this message | ||
The methods here for correcting string lengths in UTF-8 encoded serialized data weren't
reliable for me; various of the data I had stored broke them. This is the method that handled all
of my cases:
<?php
$serialized = preg_replace_callback(
'!(?<=^|;)s:(\d+)(?=:"(.*?)";(?:}|a:|s:|b:|d:|i:|o:|N;))!s',
'serialize_fix_callback',
$serialized
);
function serialize_fix_callback($match) {
return 's:' . strlen($match[2]);
}
?>
[EDITOR thiago NOTE: This note has fixes from user "w33ble"]
--was--
The methods here for correcting string lengths in UTF-8 encoded serialized data weren't
reliable for me; various of the data I had stored broke them. This is the method that handled all
of my cases:
$serialized = preg_replace_callback(
'!(?<=^|;)s:(\d+)(?=:"(.*?)";(?:}|a:|s:|b:|i:|o:|N;))!s',
'serialize_fix_callback',
$serialized
);
function serialize_fix_callback($match) {
return 's:' . strlen($match[2]);
}
http://php.net/manual/en/function.unserialize.php