In PHP, strtolower()
is a built-in function that converts a string to lowercase. It's useful when you want to ensure consistency, especially in cases like comparing strings (e.g., user inputs, email addresses, etc.) where letter casing might differ.
🔧 Syntax:
strtolower(string $string): string
- Parameter: A string you want to convert to lowercase.
- Returns: The lowercase version of the string.
✅ Example 1: Basic usage
$text = "HeLLo WoRLD!";
$lowercaseText = strtolower($text);
echo $lowercaseText;
// Output: hello world!
✅ Example 2: Email normalization
$userEmail = "John.DOE@Example.com";
$normalizedEmail = strtolower($userEmail);
echo $normalizedEmail;
// Output: john.doe@example.com
✅ Example 3: Case-insensitive comparison
$userInput = "Admin";
$expectedRole = "admin";
if (strtolower($userInput) === $expectedRole) {
echo "Access granted.";
} else {
echo "Access denied.";
}
// Output: Access granted.
📌 Notes:
strtolower()
only works with standard ASCII characters. For multibyte (Unicode) strings (like accented characters), usemb_strtolower()
instead:mb_strtolower("MÜNCHEN", "UTF-8"); // Outputs: münchen
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Copyright 2023-2025 © All rights reserved.