

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP – Case folding in a string using mb_convert_case()
mb_convert_case() is an inbuilt function in PHP that is used to perform case folding on a given string.
Syntax
string mb_convert_case(str $string, int $mode, str $encoding)
Parameters
mb_convert_case() accepts three parameters: $string, $mode and $encoding to perform case folding on a string.
$string− This parameter is used to return the string being converted.
$mode: The mode parameter is used for the mode of the conversion. It can be used for multibyte string conversion for 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 is the character encoding. If it is omitted or null, then the internal character encoding value will be used
Return Values
mb_convert_case() is used to return the string mode of the conversion.
Note: From PHP 7.3.0, some multibyte functions are added as mode, such as MB_CASE_FOLD, MB_CASE_UPPER_SIMPLE, MB_CASE_LOWER_SIMPLE, MB_CASE_TITLE_SIMPLE, and MB_CASE_FOLD_SIMPLE.
Example 1
<?php $string = "Hello World!, Welcome to the online Tutorial"; // convert above string in upper case $string = mb_convert_case($string, MB_CASE_UPPER, "UTF-8"); echo $string; // It will convert given string in lower case $string = mb_convert_case($string, MB_CASE_LOWER, "UTF-8"); echo $string; ?>
Output
HELLO WORLD!, WELCOME TO THE ONLINE TUTORIALhello world!, welcome to the online tutorial
Example 2
<?php $string = "Hello World!, Welcome to the online Tutorial"; // MB_CASE_TITLE is used $string = mb_convert_case($string, MB_CASE_TITLE, "UTF-8"); echo $string; // MB_CASE_UPPER_SIMPLE convert string in upper case $string = mb_convert_case($string, MB_CASE_UPPER_SIMPLE, "UTF-8"); echo $string; ?>
Output
Hello World!, Welcome To The Online TutorialHELLO WORLD!, WELCOME TO THE ONLINE TUTORIAL
- Related Questions & Answers
- PHP – Make a lower case string using mb_strtolower()
- PHP – Make an upper case string using mb_strtoupper()
- PHP – Get the string length using mb_strlen()
- PHP – Convert a string to a requested character encoding using iconv()
- PHP – Encode string for MIME header using mb_encode_mimeheader()
- PHP 8 – Using str_contains() to check if a string contains a substring
- PHP – How to cut out part of a string using iconv_substr()?
- Changing the case of a string using JavaScript
- Swapping string case using a binary number in JavaScript
- PHP – How to return the character count of a string using iconv_strlen()?
- PHP – How to get the selected part of a string using mb_substr()?
- How to convert a string into upper case using JavaScript?
- How match a string irrespective of case using Java regex.
- How to convert a string into the lower case using JavaScript?
- PHP – Match regular expression using mb_ereg_match()