Current Location: Home> Function Categories> mb_strtolower

mb_strtolower

Set the string to lowercase
Name:mb_strtolower
Category:Multi-byte string
Programming Language:php
One-line Description:Convert all characters in a string to lowercase

Function name: mb_strtolower()

Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7

Usage: mb_strtolower(string $str, string|null $encoding = null): string

Function Description: The mb_strtolower() function converts all characters in a string to lowercase. The difference between this function and the strtolower() function is that it correctly handles non-ASCII characters and multi-byte characters.

parameter:

  • $str (required): A string to be converted to lowercase.
  • $encoding (optional): The character encoding to use. If not specified, internal character encoding is used.

Return value: Returns a string converted to lowercase.

Example:

 $str = "HELLO WORLD!"; $lowercase = mb_strtolower($str); echo $lowercase; // 输出:hello world! $str = "你好,世界!"; $lowercase = mb_strtolower($str, "UTF-8"); echo $lowercase; // 输出:你好,世界!(由于中文字符没有大小写之分,所以不会改变)

In the example above, we first convert the string "HELLO WORLD!" to lowercase using the mb_strtolower() function and store the result in the variable $lowercase. Then, we use the echo statement to output the result to the screen, with the output as "hello world!".

In the second example, we use the mb_strtolower() function to convert the string "Hello, World!" containing Chinese characters to lowercase. Since Chinese characters do not have a case distinction, the result is the same as the original string. Note that we also specified the character encoding as "UTF-8" to ensure that multibyte characters are processed correctly.

Similar Functions
Popular Articles