PHP strtolower() Function: Syntax, Parameters, Return Value, Examples, and Usage Tips
The article explains PHP's strtolower() function, detailing its syntax, parameters, return value, and providing multiple code examples—including full string conversion, partial conversion, word-level manipulation, and multibyte handling—while also noting important considerations for case sensitivity and non‑alphabetic characters.
In PHP, the strtolower() function converts all characters in a string to lowercase. It takes a string as input and returns the transformed string.
strtolower() Function Syntax
strtolower(string $string)Parameter Description:
$string: Required. The string to be converted to lowercase.
Return Value:
Returns a new string where all characters of the original string have been converted to lowercase.
strtolower() Function Usage Example
$string = "Hello World";<br/>$lowercaseString = strtolower($string);<br/>echo $lowercaseString; // Output: hello worldIn this example, strtolower() converts the string "Hello World" to lowercase and stores the result in $lowercaseString, which is then printed.
Important Notes
strtolower()is case‑sensitive and converts uppercase letters to their lowercase equivalents based on ASCII values; lowercase letters remain unchanged.
Non‑alphabetic characters such as numbers or punctuation are left untouched.
The function can handle multibyte characters (UTF‑8), making it useful for internationalized (i18n) and localized (l10n) text.
Different Uses of strtolower()
Example 1: Convert an entire string to lowercase
$string = "Hello World";<br/>$lowercaseString = strtolower($string);<br/>echo $lowercaseString; // Output: hello worldExample 2: Convert only a part of the string to lowercase
$string = "Hello World";<br/>$lowercaseString = strtolower(substr($string, 0, 5));<br/>echo $lowercaseString; // Output: helloExample 3: Convert the first letter of each word to lowercase
$string = "Hello World";<br/>$lowercaseString = strtolower(wordwrap($string, 5, " ", true));<br/>echo $lowercaseString; // Output: hello worldExample 4: Convert all words in the string to lowercase using regex
$string = "Hello World";<br/>$lowercaseString = preg_replace('/\b\w+\b/', '${0,}', $string); // Use regex to convert words to lowercase<br/>echo $lowercaseString; // Output: hello world (same as strtolower)Example 5: Handle multibyte characters (e.g., UTF‑8 strings)
$string = "你好世界"; // UTF‑8 string containing Chinese characters<br/>$lowercaseString = strtolower($string); // Convert Chinese characters to lowercase (no change)
echo $lowercaseString; // Output: 你好世界Summary
The strtolower() function in PHP is useful for converting all characters in a string to lowercase, which is valuable for case‑insensitive text processing, handling filenames and URLs, and database queries. It also supports multibyte characters, making it suitable for internationalized applications.
PHP Learning Recommendations
Vue3+Laravel8+Uniapp Beginner to Real‑World Development Tutorial
Vue3+TP6+API Social E‑Commerce System Development Course
Swoole From Beginner to Advanced Recommended Courses
Workerman+TP6 Real‑Time Chat System Limited‑Time Offer
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
