3v4l.org

run code in 300+ PHP versions simultaneously
<?php $corrupted = <<<STRING a:4:{i:0;s:3:"three";i:1;s:5:"five";i:2;s:2:"newline1 newline2";i:3;s:6:"garçon";} STRING; $repaired = preg_replace_callback( '/s:\d+:"(.*?)";/s', function ($m) { return "s:" . strlen($m[1]) . ":\"{$m[1]}\";"; }, $corrupted ); echo $corrupted , "\n" , $repaired; echo "\n---\n"; var_export(unserialize($repaired));
Output for 7.1.25 - 7.1.27, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13, 8.1rc1 - rc3
a:4:{i:0;s:3:"three";i:1;s:5:"five";i:2;s:2:"newline1 newline2";i:3;s:6:"garçon";} a:4:{i:0;s:5:"three";i:1;s:4:"five";i:2;s:17:"newline1 newline2";i:3;s:7:"garçon";} --- array ( 0 => 'three', 1 => 'five', 2 => 'newline1 newline2', 3 => 'garçon', )

preferences:
39.13 ms | 461 KiB | 5 Q