The `strtolower()` function in PHP converts a string to lowercase. It's a fundamental string manipulation function for many versions and continues to work the same way in PHP 8.PHP 8.1 PHP 8.2 PHP 8.3 PHP and PHP 8.4 as in previous versions
Basic Syntax
<?php
strtolower(string $string): string
?>
Example Usage
<?php
$original = "Hello WORLD! PHP 8.2 is AWESOME!";
$lowercase = strtolower($original);
echo $original . "\n"; // Output: Hello WORLD! PHP 8.2 is AWESOME!
echo $lowercase . "\n"; // Output: hello world! php 8.2 is awesome
?>
Practical Example
<?php
function checkUsername($input, $stored) {
return strtolower($input) === strtolower($stored);
}
$username = "AdmhinUser";
$input = "adminuser";
if (checkUsername($input, $username)) {
echo "Username matches! (case insensitive)\n";
} else {
echo "Username does not match\n";
}
?>
The `strtolower()` function remains a reliable and efficient way to convert strings to lowercase in PHP 8.2, though for Unicode/multibyte strings, `mb_strtolower()` is recommended.