Add space in middle of string

I need to add a space after the 4th character in a string, how can i do this?

preg_replace(‘/^.{4}/’, "$0 ", $str);

ok thanks :slight_smile:

Or

substr($str, 0, 4) . " " . substr($str, 4);

Benchmark tests show that the substr method is nearly twice as fast as the preg_replace method

oh thanks, i’ll try the faster approach then :slight_smile: