Main menu

serialization

PHP serialization and line ending problem

Published by dnovikov on Tue, 12/17/2013 - 14:04

When you serialize data containing text strings which have mixed line endings ("\n" and "\r\n"), unserialization often does not work. This bug is described at

https://bugs.php.net/bug.php?id=45573

To fix the issue use json_encode around serialized string:

$data_serialized = json_encode(serialize($data));

JSON format expects explicit line ending characters displayed as user readable text in form of "\n" and "\r\n".

After that decode string back and unserialize it: