PHP strtolower() Function

Quick summary: The PHP strtolower() function converts a string to lowercase.

PHP strtolower() Syntax

strtolower(string $string): string
PHP

PHP strtolower() Basic examples

echo strtolower("Hello WORLD");
PHP
Output:
hello world

Converts all characters to lowercase.

PHP strtolower() Real-world usage

$email = "USER@EXAMPLE.COM";
echo strtolower($email);
PHP
Output:
user@example.com

Normalizes email addresses.

PHP strtolower() Edge cases

echo strtolower("ÄÖÜ");
PHP
Output:
ÄÖÜ

Non-ASCII characters are not converted correctly.

PHP strtolower() Common mistakes

Using strtolower with UTF-8 text

strtolower does not support multibyte characters.

Incorrect
echo strtolower("ÄÖÜ");
Correct
echo mb_strtolower("ÄÖÜ");

Use mb_strtolower() for UTF-8 strings.

PHP strtolower() Frequently Asked Questions

What does strtolower() do in PHP?

strtolower() converts all alphabetic characters in a string to lowercase.

Is strtolower() multibyte-safe?

No, strtolower() is not multibyte-safe. Use mb_strtolower() for UTF-8 strings.

Does strtolower() modify the original string?

No, strtolower() returns a new string and does not modify the original variable unless reassigned.

What characters are affected by strtolower()?

Only alphabetic ASCII characters are converted. Numbers and symbols remain unchanged.

What is the difference between strtolower() and mb_strtolower()?

strtolower() handles ASCII only, while mb_strtolower() supports multibyte encodings like UTF-8.

Does strtolower() work with Unicode characters?

No, strtolower() may not correctly convert Unicode characters. Use mb_strtolower() instead.

Can strtolower() be used for case-insensitive comparison?

Yes, converting both strings to lowercase allows case-insensitive comparison.

Is strtolower() fast?

Yes, strtolower() is a fast built-in function optimized for performance.

What happens if the string is already lowercase?

strtolower() returns the string unchanged if it is already lowercase.

Can strtolower() handle arrays?

No, strtolower() works only on strings. Use array_map() to apply it to arrays.

What is a real-world use case of strtolower()?

strtolower() is commonly used for normalization, such as processing emails or usernames.

How to convert an entire string to lowercase safely?

Use mb_strtolower($string, "UTF-8") for safe lowercase conversion in multibyte strings.

PHP strtolower() Related PHP Functions