Created
May 29, 2021 08:58
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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