3v4l.org

run code in 300+ PHP versions simultaneously
<?php $corrupted_byte_counts = <<<STRING s:151:"a:1:{i:0;a:4:{s:4:"name";s:15:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}}"; STRING; $repaired = preg_replace_callback( '/s:\d+:"(.*?)";/s', function ($m) { return 's:' . strlen($m[1]) . ":\"{$m[1]}\";"; }, unserialize($corrupted_byte_counts) // first unserialize string before repairing ); echo "corrupted serialized array:\n$corrupted_byte_counts"; echo "\n---\n"; echo "repaired serialized array:\n$repaired"; echo "\n---\n"; print_r(unserialize($repaired)); // unserialize repaired string echo "\n---\n"; echo serialize($repaired);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
corrupted serialized array: s:151:"a:1:{i:0;a:4:{s:4:"name";s:15:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}}"; --- repaired serialized array: a:1:{i:0;a:4:{s:4:"name";s:14:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}} --- Array ( [0] => Array ( [name] => Chloe O'Gorman [gender] => female [age] => 3_6 [present] => Something from Frozen or a jigsaw ) ) --- s:151:"a:1:{i:0;a:4:{s:4:"name";s:14:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}}";
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 corrupted serialized array: s:151:"a:1:{i:0;a:4:{s:4:"name";s:15:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}}"; --- repaired serialized array: a:1:{i:0;a:4:{s:4:"name";s:14:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}} --- Array ( [0] => Array ( [name] => Chloe O'Gorman [gender] => female [age] => 3_6 [present] => Something from Frozen or a jigsaw ) ) --- s:151:"a:1:{i:0;a:4:{s:4:"name";s:14:"Chloe O'Gorman";s:6:"gender";s:6:"female";s:3:"age";s:3:"3_6";s:7:"present";s:34:"Something from Frozen or a jigsaw ";}}";

preferences:
122.83 ms | 403 KiB | 227 Q