在php中,可以使用ucwords()函数将单词首字母进行大写转换;该函数的作用是把字符串中每个单词的首字母转换为大写,其语法为“ucwords(str)”,其参数str表示要转换的字符串,使用时只需将字符串传入str即可。
本教程操作环境:windows7系统、php7.1版,dell g3电脑
在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!
推荐学习:《php视频教程》
以上就是php语句单词首字母大写怎么转换的详细内容。