我有一个大小写不正确的字符串,如下所示:
$str = "tHis iS a StRinG thAt NeEds ProPer CapiTilization";
$newStr = ucfirst($str);
echo $newStr;
我如何能够将每个单词的第一个字母大写,并将错误的大写字母小写?我需要字符串完全是标题大小写。我知道我可以更改为降低然后使用
ucwords()
但是有没有更短的方法来做到这一点?
最佳答案
How would I be able to capitalize the first letter of each word and lower case the incorrectly capitalized letters?
ucwords()
将大写每个单词的第一个字母。您可以将其与 strtolower()
结合使用首先小写所有内容。例如:
ucwords(strtolower('HELLO WORLD!')); // Hello World!
关于php - 使所有单词小写,每个单词的第一个字母大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32564539/