在某些字符之前在字符串中添加空格

I'm*_*ant 1 php string

如何在文本字段中的字符前后放置空格?

例如. Text="John123456"

所以,我需要的是456之前的空白区域.

Sha*_*ran 5

做这样的事情

$str="John123456";
echo $str = str_replace("456"," 456",$str);
Run Code Online (Sandbox Code Playgroud)


Bil*_*ell 5

我想你在找......

substr_replace($text, ' ' . substr($text, -3), -3);
Run Code Online (Sandbox Code Playgroud)

这将用空格加上这三个字符替换字符串的最后3个字符.