Created
February 7, 2024 08:51
-
-
Save HDDen/cde4cbfdbb0eaabfa00fe8de37ac4e56 to your computer and use it in GitHub Desktop.
Fix broken serialized data (drupal metatags, for example)
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 | |
// based on https://stackoverflow.com/a/21389439/18216946 | |
$unserialized = "a:2:{s:2:"aaaaaaaaaaaaa";}"; // some potentially broken data | |
$fixed_data = preg_replace_callback ( '!s:(\d+):"(.*?)";!', function($match) { | |
return ($match[1] == strlen($match[2])) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; | |
},$unserialized ); | |
$final = unserialize($fixed_data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment