ucwords

(PHP 4, PHP 5, PHP 7)

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

说明

ucwords ( string $str [, string $delimiters = " \t\r\n\f\v" ] ) : string

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

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

参数

str

输入字符串。

delimiters

可选的 delimiters,包含了单词分割字符。

返回值

返回转换后的字符串。

更新日志

版本 说明
5.4.32, 5.5.16 增加了 delimiters 参数。

范例

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!
?>

Example #2 ucwords() 自定义 delimiters 的例子

<?php
$foo 
'hello|world!';
$bar ucwords($foo);             // Hello|world!

$baz ucwords($foo"|");        // Hello|World!
?>

注释

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

参见

相关文章
php 字符串 函数 函数把包含数据的二进制字符串转换为十六进制值php 字符串 函数 返回使用 htmlspecialchars 和 htmlentities 后的转换表php 字符串 函数 将逻辑顺序希伯来文(logical hebrew)转换为视觉顺序希伯来文(visual hebrew)php 字符串 函数 将逻辑顺序希伯来文(logical hebrew)转换为视觉顺序希伯来文(visual hebrew),并且转换换行符php 字符串 函数 转换十六进制字符串为二进制字符串php 多字节字符串 函数 对字符串进行大小写转换php 多字节字符串 函数 转换字符的编码php 多字节字符串 函数 转换一个或多个变量的字符编码php 多字节字符串 函数 使字符串大写php openssl 函数 将一个密钥的可输出表示转换为字符串php 字符串 函数 转换字符串第一个字节为 0 255 之间的值php 字符串 函数 将字符转换为 html 转义字符php 字符串 函数 将 quoted printable 字符串转换为 8 bit 字符串php 字符串 函数 将 8 bit 字符串转换成 quoted printable 字符串php 字符串 函数 将字符串转换为数组php 字符串 函数 返回字符串中单词的使用情况php 字符串 函数 将字符串的首字母转换为大写php 字符串 函数 将字符串中每个单词的首字母转换为大写php xml 解析器函数 将用 utf 8 方式编码的 iso 8859 1 字符串转换成单字节的 iso 8859 1 字符串。php xml 解析器函数 将 iso 8859 1 编码的字符串转换为 utf 8 编码
关注编程学问公众号