Function name: mb_convert_case()
Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7
Function description: mb_convert_case() function converts the character case of a string to uppercase or lowercase according to the specified conversion mode.
Syntax: string mb_convert_case ( string $str , int $mode [, string $encoding = mb_internal_encoding() ] )
parameter:
Return value: Returns the converted string.
Example:
$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!
In the above example, we use the mb_convert_case() function to perform different case conversions. First, we convert the string to uppercase, then to lowercase, then convert the first letter of each word to uppercase, and finally fold the uppercase and uppercase of the characters together. The final output results are "HELLO WORLD!", "hello world!", "Hello World!" and "hello world!" respectively.