语法

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

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

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

参数

str

输入字符串。

delimiters

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

更多: zhilu jiaocheng

示例

使用默认delimiters

<?php
echo ucwords("welcome to the onitroad tutorials website");
?>

输出:

Welcome To The Onitroad Tutorials Website

使用自定义 delimiters

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

$baz = ucwords($foo, "|");        // Hello|World!
?>
PHP String 函数ucwords()的作用是什么

PHP ucwords()函数用于将字符串中每个单词的首字母大写。

日期:2020-09-17 00:10:29 来源:oir作者:oir