Skip to content
Tutorials Center
My learning

Topics

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
<?php
echo lcfirst("HelloWorld");  // helloWorld

Try it

PHP Lowercasing the first letter

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.

PHP From PascalCase and snake_case to camelCase

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

PHP
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 combine mb_strtolower() with mb_substr().
  • It does not lowercase the rest. lcfirst("ABC") is aBC. Use strtolower() for the whole string.
  • Acronyms at the start become awkward: lcfirst("URLParser") gives uRLParser. Decide on a naming rule for them yourself.
  • Typical pair: ucwords() plus lcfirst() converts snake_case or kebab-case to camelCase.
  • Returns a new string; the argument is not modified.