Created
June 9, 2019 16:57
-
-
Save rayrutjes/b67dd5cb6d32dd889fd92791115a8667 to your computer and use it in GitHub Desktop.
Helper to fix broken PHP serialized data. Helpful mostly on broken WordPress databases.
This file contains hidden or 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 | |
$data = <<< EOF | |
The broken serialized data goes here. | |
And can expand on multiple lines. | |
EOF; | |
$data = preg_replace_callback ('!s:(\d+):"(.*?)";!', function($match) { | |
return ($match[1] == strlen($match[2])) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; | |
}, $data); | |
var_dump($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment