Skip to content

Instantly share code, notes, and snippets.

@slackero
Created May 29, 2021 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slackero/0eb23d770b6f56326efaee91c776a11c to your computer and use it in GitHub Desktop.
Save slackero/0eb23d770b6f56326efaee91c776a11c to your computer and use it in GitHub Desktop.
Fix all serialized data in an UTF-8 encoded text file (MySQL dump)
<?php
$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