3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "helloworld"; echo preg_replace('~.\L.~', ' ', $str); echo "\n---\n"; echo array_reduce(str_split($str, 2), function($carry, $item) { return $carry . $item[0] . (isset($item[1]) ? ' ' : ''); }); echo "\n---\n"; for ($offset = 1, $length = strlen($str); $offset < $length; $offset += 2) { $str[$offset] = ' '; } echo $str;
Output for 8.2.0 - 8.2.28, 8.3.0 - 8.3.19, 8.4.1 - 8.4.5
Warning: preg_replace(): Compilation failed: PCRE2 does not support \F, \L, \l, \N{name}, \U, or \u at offset 3 in /in/JuJkJ on line 5 --- h l o o l --- h l o o l

preferences:
61.39 ms | 406 KiB | 5 Q