PHP mb_lcfirst() Function

What is PHP mb_lcfirst() Function?

If you want to convert first character (no matter whether it is single byte or multi byte character) of a string to lowercase, use PHP mb_icfirst() function. So, this function converts the string “Schools of web” to “schools of web”.

When you should use mb_lcfirst() function?

If your string has a character which is not an English character, then you’ll use this function. Because, non-English characters are multi byte characters. And the functions starting with “mb_” can handle those characters correctly.

Syntax:

mb_lcfirst(string, encoding)

Parameters:

The function has 1 required parameter and 1 optional parameter-

string (Required): It specifies a string whose first character you want to convert to lowercase.

encoding (Optional): It specifies the character encoding system to use. The character encoding system encodes the string. If you omit this parameter or mention it NULL, the default character encoding system will be used. But, the default encoding may not encode the string properly (See exercise 3). You can find the default character encoding system in php.ini file in “default_charset = “ setting.

Return Values:

The function returns the input string with its first character converted to lowercase.

Examples:

Example 1:

<?php
$string = "Schools of web";
echo mb_lcfirst($string);
?>

Output:

schools of web

Example 2:

<?php
$string = "Écoles du web";
echo mb_lcfirst($string, "UTF-8");
?>

Output:

écoles du web

Explanation:

The string “Écoles du web” is in French. The function mb_lcfirst() correctly converts the first character “É” to “é”.

Notes on mb_lcfirst() Function:

Both lcfirst() and mb_lcfirst() functions can also convert the first character to lowercase of a string. But, lcfirst() function can’t do it if the character is a multi byte character.

PHP Version Support:

PHP 8 >= 8.4.0

Summary: PHP mb_lcfirst() Function

The mb_lcfirst() is a built-in multi byte string function in PHP. You can safely use this function to convert first character of a string (in any language) to lowercase.

Reference:

https://www.php.net/manual/en/function.mb-lcfirst.php