Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fix all serialized data in an UTF-8 encoded text file (MySQL dump)
$file = file_get_contents('my.sql');
function _fix_serialized($matches) {
return 's:' . strlen($matches[2]) . ':"' . $matches[2] . '";';
$file = preg_replace_callback('/s:(\d+):"(.*?)";/', '_fix_serialized', $file);
file_put_contents('my.fixed.sql', $file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment