How to fix broken serialized string in php?

From time to time previously serialized array will get broken. The most common problem occurs when string length is invalid so instead of

you have

becouse someone edited something directly in db, in this case to make php unserialize() function to work again, just do this magic:

and you will get all strings lenths to be fixed again.


  1. A more secure solution would be to use preg_replace_callback:

Leave a Reply