I have a string:
$name = ucfirst('kasiang');
I want to split it into two words and create Ka Siang
So what I tried:
echo substr_replace($name,' '.substr($name,2),2)
But i am getting only 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));
?>
You can do it with ucwords , like comment above says:
<?php
$name = ucfirst('kasiang');
echo ucwords(substr_replace($name,' '.substr($name,2),2));
Result:
Ka Siang
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.