php语句单词首字母大写怎么转换

2021-05-17 12:27:13

在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视频教程》

相关文章 大家在看