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;

preferences:
40.49 ms | 407 KiB | 5 Q