问题
Hello I have a project where I need to cApitalize only the second letter in a sentence. I now that PHP has strtoupper() and string strtoupper ( string $string ) ucfirst() returns first letter
So here is my best attempt
<?php
$str = "capitalize";
$str = ucfirst(strtolower($str)); // makes all the letters lower case
?>
This is where I get confused if 0 = the first letter and 1= 2nd then could I just make an array(")
or count_chars()
then $val
回答1:
Its a old question, just came across this so would put an answer based on @doppelgreener comment.
This should work :
$str = "capitalize";
$str[1]= strtoupper($str[1]);
echo $str; // cApitalize
回答2:
i have one idea to perform this operation.. example
$strmain='capitalize';
$result = substr($strmain, 0, 1); //result is c
$result1=str_replace($result,'',$strmain);//now your result1 is apitalize
$result2=ucfirst($result1); //now result2 is Apitalize
$finalresult=$result.$result2 ///now your finalresult is cApitalize
来源:https://stackoverflow.com/questions/16829362/php-capitalize-second-letter-in-sentence-min-10-characters-long