牛牛在线工具

mb_convert_case()

收录 8868 个 PHP 函数,含用途说明与用法示例。

mb_convert_case()

将字符串的字符大小写转换为大写或小写,根据指定的转换模式

函数名称:mb_convert_case() 适用版本:PHP 4 >= 4.3.0, PHP 5, PHP 7 函数描述:mb_convert_case() 函数将字符串的字符大小写转换为大写或小写,根据指定的转换模式。 语法:string mb_convert_case ( string $str , int $mode [, string $encoding = mb_internal_encoding() ] ) 参数: $str:要转换大小写的字符串。 $mode:转换模式,可选择以下四个常量之一: MB_CASE_UPPER:将字符串中的所有字符转换为大写。 MB_CASE_LOWER:将字符串中的所有字符转换为小写。 MB_CASE_TITLE:将字符串中的每个单词的首字母转换为大写。 MB_CASE_FOLD:将字符串中的字符转换为小写,并将字符的大小写折叠在一起。 $encoding:可选参数,指定字符编码,默认为 mb_internal_encoding() 函数返回的内部字符编码。 返回值:返回转换后的字符串。 示例: $str = "Hello World!"; $upperCase = mb_convert_case($str, MB_CASE_UPPER); $lowerCase = mb_convert_case($str, MB_CASE_LOWER); $titleCase = mb_convert_case($str, MB_CASE_TITLE); $foldCase = mb_convert_case($str, MB_CASE_FOLD); echo $upperCase; // 输出:HELLO WORLD! echo $lowerCase; // 输出:hello world! echo $titleCase; // 输出:Hello World! echo $foldCase; // 输出:hello world! 以上示例中,我们将字符串 "Hello World!" 使用 mb_convert_case() 函数进行不同的大小写转换。首先,我们将字符串转换为大写,然后转换为小写,接着将每个单词的首字母转换为大写,最后将字符的大小写折叠在一起。最终输出的结果分别是 "HELLO WORLD!"、"hello world!"、"Hello World!" 和 "hello world!"。