what to do when unserialize fails
Using PHP’s serialize function to serialize and array or object where some element is a string with UTF8 data creates the serialized string properly. However, unserialize function fails to unpack that data.
The solution I find to work (not sure if it’s perfect though) is to use mb_unserialize function (found in comments of PHP manual).
function mb_unserialize($serial_str) {
$out = preg_replace('!s:(\d+):"(.*?)";!se',
"'s:'.strlen('$2').':\"$2\";'", $serial_str );
return @unserialize($out);
}
Works as advertised if your database is not UTF-8, which should be the case.
Source: backwardcompatible.net