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; echo $corrupted; echo "\n---\n"; echo "fails to allow newline characers:\n"; var_export(unserialize(preg_replace_callback('!s:(\d+):"(.*?)";!', function($m) { return 's:'.mb_strlen($m[2]).':"'.$m[2].'";'; }, $corrupted))); echo "\n\nfails to appropriately count bytes:\n"; var_export(unserialize(preg_replace_callback('!s:(\d+):"(.*?)";!s', function($m) { return 's:'.mb_strlen($m[2]).':"'.$m[2].'";'; }, $corrupted))); echo"\n---\n"; echo "USE THIS PATTERN WITH THIS REPLACEMENT:\n"; var_export(preg_replace_callback( '/s:\d+:"(.*?)";/s', function ($m) { return "s:" . strlen($m[1]) . ":\"{$m[1]}\";"; }, $corrupted ));
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 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";} --- fails to allow newline characers: Notice: unserialize(): Error at offset 47 of 83 bytes in /in/Cf6Nh on line 11 false fails to appropriately count bytes: Notice: unserialize(): Error at offset 80 of 84 bytes in /in/Cf6Nh on line 14 false --- USE THIS PATTERN WITH THIS REPLACEMENT: 'a:4:{i:0;s:5:"three";i:1;s:4:"five";i:2;s:17:"newline1 newline2";i:3;s:7:"garçon";}'
Output for 7.3.32 - 7.3.33
a:4:{i:0;s:3:"three";i:1;s:5:"five";i:2;s:2:"newline1 newline2";i:3;s:6:"garçon";} --- fails to allow newline characers: false fails to appropriately count bytes: false --- USE THIS PATTERN WITH THIS REPLACEMENT: 'a:4:{i:0;s:5:"three";i:1;s:4:"five";i:2;s:17:"newline1 newline2";i:3;s:7:"garçon";}'

preferences:
25.54 ms | 461 KiB | 5 Q