导航首页 » 技术教程 » PHP字符串函数ucwords()的用法
PHP字符串函数ucwords()的用法 150 2023-12-12   

ucwords

(PHP 4, PHP 5)

ucwords — 将字符串中每个单词的首字母转换为大写

说明

string ucwords ( string $str )

str 中每个单词的首字符(如果首字符是字母)转换为大写字母,并返回这个字符串。

这里单词的定义是紧跟在空白字符(空格符、制表符、换行符、回车符、水平线以及竖线)之后的子字符串。

参数

str

输入字符串。

返回值

返回转换后的字符串。

范例

Example #1 ucwords() 范例

<?php
$foo = 'hello world!';
$foo = ucwords($foo);             // Hello World!

$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>

注释

Note: 此函数可安全用于二进制对象。

参见

strtoupper() - 将字符串转化为大写 strtolower() - 将字符串转化为小写 ucfirst() - 将字符串的首字母转换为大写 mb_convert_case() - 对字符串进行大小写转换


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103