PHP Reference Β· String Functions
PHP lcfirst() function
Reference for PHP lcfirst(): make the first character of a string lowercase, ASCII-only behavior, and typical uses such as camelCase and property names.
lcfirst() returns a copy of a string with its first byte converted to lowercase if it is an uppercase ASCII letter. Everything after the first character is untouched. It is the mirror image of ucfirst().
A common use is building identifiers: turning UserName into userName for a camelCase variable or JSON key.
<?php echo lcfirst("HelloWorld"); // helloWorld
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input Β· what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input Β· what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.
Syntax
lcfirst(string $string): string
| Name | Description |
|---|---|
$string |
The input string. |
Return value: the string with the first character lowercased if it is an ASCII uppercase letter, otherwise the string unchanged.
Usage notes
- ASCII only. Since PHP 8.2 the function ignores the locale;
Γat the start staysΓ. For other scripts combinemb_strtolower()withmb_substr(). - It does not lowercase the rest.
lcfirst("ABC")isaBC. Usestrtolower()for the whole string. - Acronyms at the start become awkward:
lcfirst("URLParser")givesuRLParser. Decide on a naming rule for them yourself. - Typical pair:
ucwords()pluslcfirst()converts snake_case or kebab-case to camelCase. - Returns a new string; the argument is not modified.
Related
ucfirst(),ucwords(),strtolower(),mb_strtolower()- Lessons: Strings, String functions