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