Friday, October 10, 2025
HomeLanguagesPHP mb_convert_case() Function

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 neveropen";
  
    // 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 neveropen

Example 2: The following code demonstrates another example of the PHP mb_convert_case() function.

PHP




<?php
  
    // Declare a string
    $str = "welcome to neveropen";
  
    // 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 Geeksforneveropen
WELCOME TO GEEKSFORGEEKS

Reference: https://www.php.net/manual/en/function.mb-convert-case.php

RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7100 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS