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) . \'
You can use chunk_split [docs]:
$str = chunk_split($rows['value'], 4, ' ');
DEMO
If the length of the string is a multiple of four but you don't want a trailing space, you can pass the result to trim.