Converting String to Lowercase in PHP

To convert a string to lowercase in PHP, you can use the strtolower($string) function. The strtolower() function takes a string as a parameter and converts all uppercase English characters to lowercase. To convert non-English characters to lowercase, you can use the mb_strtolower() function. All other numeric characters or special characters in the string are left unchanged. In this PHP String to Lowercase example, we convert a string to lowercase using the strtolower() function. Click Execute to run the PHP Lowercase String Example online and see the result.
Converting String to Lowercase in PHP Execute
<?php
echo strtolower('Hello World!');
?>
Updated: Viewed: 10339 times

What is a string in PHP?

PHP strings are sequences of characters, where each character is represented by one byte. A byte can only contain 256 characters, so Unicode strings are not natively supported in PHP. In PHP, you can create strings using single quotes ('...'), double quotes ("..."), and Heredoc syntax (<<<). PHP provides a rich set of built-in functions for replacing, concatenating, comparing, interpolating, and splitting strings. You can also find the length of a string, convert the string to int, and convert the string to array.

How to make PHP string lowercase?

To convert the PHP string to lowercase, you can use the strtolower() function. The following is the syntax of the strtolower() function:

PHP strtolower() Syntax
strtolower(string)

Where:
  • string: specifies the string to be converted to lowercase
PHP strtolower() Example
<?php
echo strtolower('PHP String');
?>

#output: php string

PHP String to Lowercase Examples

The following are examples of converting string to lowercase in PHP:

Converting string to lowercase

The following is an example of converting a PHP string to lowercase using strtolower():

PHP String to Lowercase Example
<?php
echo strtolower('PHP Lowercase String Example');
?>

#output: php lowercase string example

Converting non-English characters to lowercase

To convert non-English characters to lowercase in PHP, you can use the mb_strtolower() function:

PHP non-English String to Lowercase Example
<?php
echo mb_strtolower('ԲԱՐԵՒ ԱՇԽԱՐՀ!');
?>

#output: բարեւ աշխարհ!

Converting special characters to lowercase

To convert special characters to lowercase in PHP, you can use the mb_strtolower() function:

PHP Special Characters to Lowercase Example
<?php
echo mb_strtolower('Characters: Ü, É, Ä');
?>

#output: characters: ü, é, ä

Converting the first character of a string to lowercase

To convert the first character of a string to lowercase in PHP, you can use the lcfirst() function:

PHP First Character to Lowercase Example
<?php
echo lcfirst('PHP String');
?>

#output: pHP String

Converting multibyte non-ASCII characters to lowercase

To convert multibyte non-ASCII characters to lowercase, you can use the mb_strtolower() function. The bytes in the range "A" (0x41) to "Z" (0x5a) will be converted to lowercase letters by adding 32 to each value. This can be used to convert ASCII characters to UTF-8 encoded strings, as UTF-8 multibyte characters will be ignored.

PHP Multibyte non-ASCII Characters to Lowercase Example
<?php
echo mb_strtolower('PASIÓN');
?>

#output: pasión

How to convert string to uppercase in PHP?

To convert a PHP string to uppercase, you can use the strtoupper() function:

PHP String to Uppercase Example
<?php
echo strtoupper('php string');
?>

#output: PHP STRING

See also