serialize() function returns a string representation of an array or object. Using serialize on an object will preserve the name of the class and all of its properties, however the methods are not saved.
To return the string representation back, use the
unserialize() function. It is convenient to store the serialized string in a database or in a text file.
Sometimes, due to different encodings, the unserialize function throws an error like:
Notice: unserialize (): Error at offset 234 of 5455 bytes in ... at line ...
The way to eliminate it:
$text = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $text); $array = unserialize($text); var_dump($array);
But this method does not always help, so the string should be additionally base64 encoded before saving.