lcfirst()
Our article is about the PHP function lcfirst(), which is used to convert the first character of a string to lowercase. This function is useful for working with
The PHP lcfirst() function makes the first character of a string lowercase and returns the modified string. Only the very first character is touched — the rest of the string is left exactly as it is. This page covers its syntax, return value, behavior with non-letters and Unicode, and the common situations where it is useful.
Syntax
lcfirst(string $string): stringIt accepts a single required parameter and returns a new string — lcfirst() does not modify the original variable in place.
| Parameter | Description |
|---|---|
$string | The input string whose first character should be lowercased. |
Return value: the resulting string with its first character lowercased.
Basic example
Only the leading H changes; the rest stays untouched:
hello World!When would I use it?
lcfirst() is small but handy whenever the first character carries meaning:
- Generating camelCase identifiers. Turn
GetUserNameintogetUserNamefor method or property names. - Normalizing user input that may arrive capitalized when you store it lowercased.
- Sentence/list formatting, where the first word of a fragment should not start with a capital letter.
<?php
// PascalCase -> camelCase
echo lcfirst("UserProfile"); // userProfile
?>userProfileBehavior with non-letters and already-lowercase input
If the first character is not an uppercase letter — a digit, symbol, space, or an already-lowercase letter — lcfirst() returns the string unchanged.
<?php
echo lcfirst("Hello"), "\n"; // hello
echo lcfirst("123ABC"), "\n"; // 123ABC (first char is a digit)
echo lcfirst(" Hello"), "\n"; // " Hello" (leading space is unchanged)
echo lcfirst(""), "\n"; // "" (empty string)
?>hello
123ABC
Hello
Gotcha: lcfirst() is byte-based, not Unicode-aware
lcfirst() only handles single-byte ASCII letters. Multibyte characters such as accented or non-Latin letters are not lowercased correctly, because the function operates on the first byte rather than the first character.
<?php
echo lcfirst("Élan"); // stays "Élan" (É is multibyte)
?>ÉlanFor multibyte strings, lowercase the first character yourself with mb_strtolower() and mb_substr():
<?php
$str = "Élan";
$first = mb_strtolower(mb_substr($str, 0, 1), "UTF-8");
echo $first . mb_substr($str, 1); // élan
?>élanRelated functions
ucfirst()— the opposite: makes the first character uppercase.ucwords()— uppercases the first letter of every word.strtolower()— lowercases the entire string.strtoupper()— uppercases the entire string.