I want to add a space to some output after every 4th character until the end of the string. I tried:
$str = $rows[\'value\'];
echo substr($str, 0, 4) . \'
Wordwrap does exactly what you want:
echo wordwrap('12345678' , 4 , ' ' , true )
will output: 1234 5678
If you want, say, a hyphen after every second digit instead, swap the "4" for a "2", and the space for a hyphen:
echo wordwrap('1234567890' , 2 , '-' , true )
will output: 12-34-56-78-90
Reference - wordwrap