[英]Capitalize two letters after splitting the string into two words
I have a string: 我有一个字符串:
$name = ucfirst('kasiang');
I want to split it into two words and create Ka Siang
我想将其分为两个词并创建Ka Siang
So what I tried: 所以我尝试了:
echo substr_replace($name,' '.substr($name,2),2)
But i am getting only Ka siang
. 但是我只得到Ka siang
。 Is there any way to capitalize second letter too? 还有什么办法可以大写第二个字母吗?
You can do like below. 您可以像下面这样。
<?php
$name = ucfirst('kasiang');
echo substr_replace($name,' '.ucfirst(substr($name,2)),2);
?>
Another way is: 另一种方法是:
<?php
echo ucwords(substr_replace($name,' '.substr($name,2),2));
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.