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 = "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!"。