Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PHP - lcfirst() Function



The PHP lcfirst() function is used to convert the first character of a given string to lowercase. The term "lowercase" refers to small letter characters such as a, b, c ....z.

This function will only convert the first character of the first word in the given string to lowercase, even if the string contains multiple words.

For example, if we have the string "Hi, How are you?", the resultant string will be "hi, How are you?", rather than "hi, how are you?".

Syntax

Following is the syntax of the PHP lcfirst() function −

lcfirst(string $str): string

Parameters

Following is the parameter of this function −

  • str − The input string.

Return Value

This function returns a string with first letter in lowercase.

Example 1

The following is the basic example of the PHP lcfirst() function −

<?php
   $str = "Tutorialspoint";
   echo "The original string: $str";
   echo "\nThe resultant string: ";
   #using lcfirst() function
   echo lcfirst($str);
?>

Output

The above program produces the following output −

The original string: Tutorialspoint
The resultant string: tutorialspoint

Example 2

If the first character of the given string is already in lowercase, the original string will not be affected.

Here is another example of using the PHP lcfirst() function. We use this function to convert the first character of this string "Hello World" to lowercase −

<?php
   $str = "hello World";
   echo "The original string: $str";
   echo "\nThe resultant string: ";
   #using lcfirst() function
   echo lcfirst($str);
?>

Output

After executing the above program, the following output will be displayed −

The original string: hello World
The resultant string: hello World
php_function_reference.htm
Advertisements