Welcome to our PHP mb_strtolower() tutorial! In this lesson, we'll explore how to convert strings to lowercase using the Multi-Byte String (MB) functions in PHP. π Note: This function is particularly useful when dealing with non-English characters.
The syntax for using mb_strtolower() is as follows:
mb_strtolower($string, $encoding);$string: The string you want to convert to lowercase.$encoding: The character encoding of the input string. If omitted, PHP will assume UTF-8.Let's convert a simple string to lowercase.
$text = "Hello, World!";
$lowercase_text = mb_strtolower($text);
echo $lowercase_text; // Output: "hello, world!"When working with non-UTF-8 encoded strings, you'll need to specify the encoding.
$text = "δ½ ε₯½οΌδΈηοΌ"; // Chinese text with ISO-8859-1 encoding
$encoding = 'ISO-8859-1';
$lowercase_text = mb_strtolower($text, $encoding);
echo $lowercase_text; // Output: "δ½ ε₯½οΌδΈηοΌ" (lowercase in Chinese)What does the PHP mb_strtolower() function do?
Happy Coding! β