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



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![]()



Or
PHP Code:substr($str, 0, 4) . " " . substr($str, 4);
Benchmark tests show that the substr method is nearly twice as fast as the preg_replace method
Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona



oh thanks, i'll try the faster approach then![]()
Bookmarks