PHP strtolower

Summary: in this tutorial, you’ll learn how to use the PHP strtolower() function to make the lowercase version of a string.

Introduction to the PHP strtolower() function

The strtolower() function accepts a string and returns a new string with all alphabetic characters converted to lowercase.

Here’s the syntax of the strtolower() function:

strtolower ( string $string ) : stringCode language: PHP (php)

The strtolower() uses the current locale to determine alphabetic characters.

To return a new string with a specific encoding with all alphabetic characters converted to lowercase, you use the mb_strtolower() function instead:

mb_strtolower ( string $string , string|null $encoding = null ) : stringCode language: PHP (php)

The following defines a lower() function that returns a new string with all characters converted lowercase:

<?php

if (!function_exists('lower')) {
    function lower(string $value) : string
    {
        return mb_strtolower($value, 'UTF-8');
    }
}Code language: PHP (php)

PHP strtolower() function examples

The following example uses the strtolower() function to convert the string PHP to lowercase:

<?php

echo strtolower('PHP');Code language: PHP (php)

Output:

phpCode language: PHP (php)

Summary

  • Use the strtolower() function to return a new string from a string with all characters converted to lowercase.
  • Use the mb_strtolower() for a string with a specific encoding.
Did you find this tutorial useful?