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

PHP - strtolower() Function



The PHP strtolower() function is used to convert all alphabetic characters (i.e., A to Z) to lowercase in the given string. The term "lowercase" refers to the "small letter" characters in the alphabet series, such as a, b, c, ... z.

If the given string is already in lowercase, this function will not affect the original string and will remain unchanged.

Syntax

Following is the syntax of PHP strtolower() function −

strtolower(string $str): string

Parameters

This function accepts a single parameter, which is described below −

  • str: The input string that needs to be converted to lowercase."

Return Value

This function returns the string with all alphabetic characters converted to lowercase.

Example 1

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

<?php
   $str = "TUTORIALSPOINT";
   echo "The given string: $str";
   echo "\nThe string after converting into lowercase: ";
   #using strtolower() function
   echo strtolower($str);
?>

Output

The above program produces the following output −

The given string: TUTORIALSPOINT
The string after converting into lowercase: tutorialspoint

Example 2

Here is another example of using the PHP strtolower() function. This function converts all alphabetic characters in the given string "Hello World!" into lowercase −

<?php
   $str = "Hello World!";
   echo "The given string: $str";
   echo "\nThe string after converting into lowercase: ";
   #using strtolower() function
   echo strtolower($str);
?>

Output

Following is the output of the above program −

The given string: Hello World!
The string after converting into lowercase: hello world!

Example 3

If the given string is already in lowercase, the PHP strtolower() function will not affect the original string, and it will remain unchanged −

<?php
   $str = "hey!, how are you";
   echo "The given string: $str";
   echo "\nThe string after converting into lowercase: ";
   #using strtolower() function
   echo strtolower($str);
?>

Output

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

The given string: hey!, how are you
The string after converting into lowercase: hey!, how are you
php_function_reference.htm
Advertisements