Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
PHP – Make a lower case string using mb_strtolower()
In PHP, we can use the function mb_strtolower() to change a given string into lower case. It returns strings with all alphabetic characters converted to lowercase characters, with proper support for multibyte character encodings.
Syntax
string mb_strtolower(string $string, ?string $encoding = null)
Parameters
mb_strtolower() accepts two parameters: $string and $encoding.
$string − The string being lowercased, returns strings with all alphabetic characters converted to lowercase characters.
$encoding − This parameter is the character encoding. If it is absent or null, then the internal character encoding value will be used.
Return Values
string with all alphabetic characters converted to lowercase.
Example
Here's how to convert a string to lowercase using mb_strtolower() −
<?php
// Upper and lower case characters are used to
// convert in lower case using mb_strtolower function
$string = "Hello World!, Welcome to ONLINE tutorials";
// It gives the output in lower case
$string = mb_strtolower($string);
echo $string;
?>
hello world!, welcome to online tutorials
Example with Encoding
You can also specify the character encoding explicitly −
<?php
$string = "CAFÉ NAÏVE";
// Convert to lowercase with UTF-8 encoding
$lowercase = mb_strtolower($string, 'UTF-8');
echo $lowercase;
?>
café naïve
Conclusion
The mb_strtolower() function is ideal for converting strings to lowercase while preserving multibyte characters. Always specify encoding when working with international characters to ensure proper conversion.
