php语句单词首字母大写怎么转换
时间:2021-05-24
来源:互联网
今天PHP爱好者为您带来在PHP中,可以使用ucwords()函数将单词首字母进行大写转换;该函数的作用是把字符串中每个单词的首字母转换为大写,其语法为“ucwords(str)”,其参数str表示要转换的字符串,使用时只需将字符串传入str即可。希望对大家有所帮助。
php语句单词首字母大写怎么转换
本教程操作环境: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爱好者其它相关文章!
-
C++中优先队列priority_queue详解(定义、基本用法、常用操作、实例) 时间:2025-05-04
-
MySQL case when详解(基本用法、示例) 时间:2025-05-04
-
MySQL DATE_FORMAT函数详解(定义、用法、实例) 时间:2025-05-04
-
Linux中zip压缩命令详解(参数、原理、使用方法、示例、常见问题) 时间:2025-05-04
-
Java中iterator迭代器详解(定义、工作原理、用法、遍历集合) 时间:2025-05-04
-
CodeBlocks是干什么的 CodeBlocks下载和使用教程 时间:2025-05-04
今日更新
-
win10忘记登录密码怎么办
阅读:18
-
php怎么判断字符串含不含中文
阅读:18
-
css怎么设置最大高度
阅读:18
-
php如何找到php.ini
阅读:18
-
css里form用法是什么
阅读:18
-
php怎么将字符串转为timestamp(时间戳)
阅读:18
-
zabbix php无法显示怎么办
阅读:18
-
php变量输出乱码怎么办
阅读:18
-
MySQL架构组件是什么
阅读:18
-
centos安装php开发环境
阅读:18