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 8.3.0 - 8.3.4, 8.3.6
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: Warning: unserialize(): Error at offset 47 of 83 bytes in /in/Cf6Nh on line 11 false fails to appropriately count bytes: Warning: 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 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 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: Warning: unserialize(): Error at offset 47 of 83 bytes in /in/Cf6Nh on line 11 false fails to appropriately count bytes: Warning: 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 5.6.32, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18
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:
169.76 ms | 402 KiB | 212 Q