PHP mb_strtolower() Tutorial 🎯

beginner
12 min

PHP mb_strtolower() Tutorial 🎯

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.

What is mb_strtolower()? πŸ’‘ Pro Tip: mb_strtolower() is a PHP function that converts a multi-byte string to lowercase.

Why Use mb_strtolower()? πŸ“ Note: mb_strtolower() is essential for handling languages that use non-Latin characters, like Chinese, Japanese, and Korean.

mb_strtolower() Syntax

The syntax for using mb_strtolower() is as follows:

php
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.

Example 1: Basic Usage

Let's convert a simple string to lowercase.

php
$text = "Hello, World!"; $lowercase_text = mb_strtolower($text); echo $lowercase_text; // Output: "hello, world!"

Example 2: Custom Encoding

When working with non-UTF-8 encoded strings, you'll need to specify the encoding.

php
$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)

Quiz

Quick Quiz
Question 1 of 1

What does the PHP mb_strtolower() function do?

Conclusion πŸ’‘ Pro Tip: Practice using mb_strtolower() to ensure your PHP applications are compatible with all languages and character sets.

Happy Coding! βœ