PHP lcfirst() Function

What is PHP lcfirst() Function?

If you want to make the first character of a string lowercase, use lcfirst() function.

Syntax:

lcfirst(string)

Parameters:

The Function has 1 parameter which is required-

string (Required): It specifies the string.

Return Values:

It returns a string whose first character is lowercase.

Examples:

Example 1:

<?php
$string = "Schools of web";
echo "Original string: " . $string . "<br />";
$string = lcfirst($string); 
echo "After converting the first character lowercase: " . $string;
?>

Output:

Original string: Schools of web
After converting the first character lowercase: schools of web

Example 2:

<?php
$String = "Schools of web";
$NewString = lcfirst($String); 
echo $String; echo "<br />";
echo $NewString;
?>

Output:

Schools of web
schools of web

Notes on lcfirst() Function:

  • The function works only on ASCII characters and if it is between A to Z. If the first character is a multi-byte character, you can use mb_lcfirst() function.
  • The function leaves the string unchanged if-
    • The 1st character is already lowercase or
    • Non alphabetic character.
  • The function doesn’t modify the original string.
  • The function leaves the remaining characters unchanged.

Related Function:

  • ucfirst() – To make first character uppercase.
  • ucfirst() – To make first character of each word uppercase.
  • strtoupper() – To make all the characters of a string uppercase.
  • strtolower() – To make all the characters of a string lowercase.

PHP Version Support:

PHP 4, PHP 5, PHP 7, PHP 8

Summary: PHP lcfirst() Function

lcfirst() function is one of the built-in string functions. Use this function to convert the 1st character of a string lowercase.

Reference:

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