ucwords
将字符串中每个单词的首字母转换为大写
PHP 4, PHP 5, PHP 7, PHP 8 及以上版本均支持
ucwords() 函数将字符串中每个单词的首字母转换为大写,其余字母保持不变。
string ucwords(string $str)
返回经过转换后的字符串,字符串中每个单词的首字母均为大写。
示例代码:
<?php
$text = "hello world! this is php.";
echo ucwords($text);
?>
示例中字符串 "hello world! this is php." 被传入 ucwords() 函数,函数返回的结果是 "Hello World! This Is Php.",即每个单词的首字母都被转换成了大写。