Skip to content

Instantly share code, notes, and snippets.

@D4R4
Created August 5, 2019 08:12
Show Gist options
  • Save D4R4/e322ab5d8bd1013175108bc1acfe32e8 to your computer and use it in GitHub Desktop.
Save D4R4/e322ab5d8bd1013175108bc1acfe32e8 to your computer and use it in GitHub Desktop.
PHP corrupted serialized string fixer, usefull for Wordpress options data
function serialize_corrector($serialized_string){
// at first, check if "fixing" is really needed at all. After that, security checkup.
if ( @unserialize($serialized_string) !== true && preg_match('/^[aOs]:/', $serialized_string) ) {
$serialized_string = preg_replace_callback( '/s\:(\d+)\:\"(.*?)\";/s', function($matches){return 's:'.strlen($matches[2]).':"'.$matches[2].'";'; }, $serialized_string );
}
return $serialized_string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment