PHP Reference Β· String Functions
PHP strtolower() function
Reference for PHP strtolower(): convert a string to lowercase, why it only handles ASCII letters since PHP 8.2, and when to use mb_strtolower() instead.
strtolower() returns a copy of a string with every uppercase ASCII letter (A to Z) converted to lowercase. Other bytes are left alone.
Before PHP 8.2 the result depended on the current locale, which could change which bytes were treated as letters. Since PHP 8.2 the function is locale-insensitive and affects ASCII only. For accented or non-Latin letters use mb_strtolower().
<?php echo strtolower("Hello WORLD"); // hello world
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input Β· what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input Β· what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.
Syntax
strtolower(string $string): string
| Name | Description |
|---|---|
$string |
The input string. |
Return value: the lowercase string.
Usage notes
- ASCII only since PHP 8.2. Earlier versions followed
setlocale(). Do not depend on locale-specific behavior. - Multibyte text:
strtolower("Γ")returns"Γ"unchanged. Usemb_strtolower()and make sure your source encoding is UTF-8. - Comparing strings: instead of lowercasing both sides,
strcasecmp()is clearer. Remember that case-insensitive search for non-ASCII text needs themb_functions. - Normalization before storage: lowercase emails and slugs, but do not assume the local part of an address is case-insensitive in every system.
- Related functions:
strtoupper(),ucfirst(),ucwords(),lcfirst(). - Special language rules (Turkish dotted and dotless i, Greek final sigma) are not handled by
strtolower().
Related
strtoupper(),mb_strtolower(),lcfirst(),strcasecmp()- Lessons: Strings, Multibyte strings