Current Location: Home> Function Categories> mb_convert_case

mb_convert_case

Convert a string case
Name:mb_convert_case
Category:Multi-byte string
Programming Language:php
One-line Description:Convert the character case of a string to uppercase or lowercase according to the specified conversion mode

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:

  • $str: The string to convert case.
  • $mode: Convert mode, you can select one of the following four constants:
    • MB_CASE_UPPER: Converts all characters in the string to uppercase.
    • MB_CASE_LOWER: Converts all characters in a string to lowercase.
    • MB_CASE_TITLE: Converts the first letter of each word in the string to uppercase.
    • MB_CASE_FOLD: Converts characters in a string to lowercase and folds the upper and lowercase characters together.
  • $encoding: Optional parameter, specify character encoding, default is the internal character encoding returned by the mb_internal_encoding() function.

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.

Similar Functions
Popular Articles