PHP ucwords() 函数

(PHP 4, PHP 5, PHP 7)

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

定义和用法

ucwords() 函数把字符串中每个单词的首字符转换为大写。

注释:该函数是二进制安全的。

相关函数:

语法

ucwords ( string $str [, string $delimiters = " \t\r\n\f\v" ] ) : string
参数 描述
string 必需。规定要转换的字符串。
string 可选的 delimiters,包含了单词分割字符。

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

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

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