在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!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。