在PHP中,可以使用ucwords()函数将单词首字母进行大写转换。
ucwords() 函数把字符串中每个单词的首字符转换为大写。
注释:该函数是二进制安全的。
语法
ucwords(string)
参数string :必需。规定要转换的字符串。
返回值:返回已转换的字符串。
代码示例:
<?php $foo = 'hello world!'; $foo = ucwords($foo); // Hello World! echo $foo."<br>"; $bar = 'HELLO WORLD!'; $bar = ucwords($bar); // HELLO WORLD! echo $bar."<br>"; $bar = ucwords(strtolower($bar)); // Hello World! echo $bar; ?>
输出:
Hello World! HELLO WORLD! Hello World!