Open In App

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:

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
  
    // Declare a string
    $str = "welcome to geeksforgeeks";
  
    // 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 geeksforgeeks

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




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

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


Article Tags :