PHP mb_convert_case() Function

The mb_convert_case() function is an inbuilt function in PHP that is used to perform case folding on the string and converted it into the specified mode of string.
Syntax:
string mb_convert_case(
string $string,
int $mode,
string $encoding = null
)
Parameters: This function accepts three parameters that are described below:
- $string: This parameter defines the string that needs to convert into a specified mode.
- $mode: This parameter holds the mode of conversion. The mode of conversion can be:
- MB_CASE_UPPER
- MB_CASE_LOWER
- MB_CASE_TITLE
- MB_CASE_FOLD
- MB_CASE_UPPER_SIMPLE
- MB_CASE_LOWER_SIMPLE
- MB_CASE_TITLE_SIMPLE
- MB_CASE_FOLD_SIMPLE
- $encoding: This parameter describes the character encoding. If this parameter value is omitted or null, the internal character encoding value will be used.
Return Value: This parameter returns the case folded version of the string converted into the specified mode.
Example 1: The following code demonstrates the PHP mb_convert_case() function.
PHP
<?php // Declare a string $str = "welcome to zambiatek"; // Convert given string into upper // case using "UTF-8" encoding $upperCase = mb_convert_case( $str, MB_CASE_UPPER, "UTF-8"); // Print upper case string echo $upperCase; // Convert string into lower case // using "UTF-8" encoding $lowerCase = mb_convert_case( $upperCase, MB_CASE_LOWER, "UTF-8"); // Print lower case string echo "\n" . $lowerCase; ?> |
Output
WELCOME TO GEEKSFORGEEKS welcome to zambiatek
Example 2: The following code demonstrates another example of the PHP mb_convert_case() function.
PHP
<?php // Declare a string $str = "welcome to zambiatek"; // Convert given string into case // title using "UTF-8" encoding $upperCase = mb_convert_case( $str, MB_CASE_TITLE, "UTF-8"); // Print upper case string echo $upperCase; // Convert string into case upper // simple using "UTF-8" encoding $lowerCase = mb_convert_case( $upperCase, MB_CASE_UPPER_SIMPLE, "UTF-8"); // Print lower case string echo "\n" . $lowerCase; ?> |
Output
Welcome To Geeksforzambiatek WELCOME TO GEEKSFORGEEKS
Reference: https://www.php.net/manual/en/function.mb-convert-case.php



