From time to time previously serialized array will get broken. The most common problem occurs when string length is invalid so instead of
1 |
a:2:{i:758;s:4:"test";i:759;s:4:"test";} |
you have
1 |
a:2:{i:758;s:4:"test";i:759;s:9:"test";} |
becouse someone edited something directly in db, in this case to make php unserialize() function to work again, just do this magic:
1 2 3 |
$data = html_entity_decode($data, ENT_QUOTES, 'UTF-8'); $data = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $data ); $data = unserialize($data); |
and you will get all strings lenths to be fixed again.
Parse error: syntax error, unexpected ‘;’, expecting T_PAAMAYIM_NEKUDOTAYIM
A more secure solution would be to use preg_replace_callback: