Current Location: Home> Function Categories> mb_strtoupper

mb_strtoupper

Set the string to uppercase
Name:mb_strtoupper
Category:Multi-byte string
Programming Language:php
One-line Description:Convert all characters in the string to capital letters and return the converted string

Function name: mb_strtoupper()

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

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

The mb_strtoupper() function converts all characters in a string to uppercase letters and returns the converted string. This function is similar to the strtoupper() function, but also works for non-ASCII characters.

parameter:

  • $str: The string to be converted.
  • $encoding (optional): Specify character encoding. If not provided, internal character encoding is used.

Return value: Returns the string converted to capital letters.

Example:

 $str = "hello world!"; $result = mb_strtoupper($str); echo $result; // 输出: HELLO WORLD! $str = "你好,世界!"; $result = mb_strtoupper($str, 'UTF-8'); echo $result; // 输出: 你好,世界!(因为大写字母只适用于ASCII字符)

Notes:

  • The mb_strtoupper() function depends on the mbstring extension. If this extension is not installed, the function will not be used.
  • If the default character encoding is not set before the function call, you can set the default encoding by calling the mb_internal_encoding() function.
  • If the string you are dealing with contains multibyte characters (such as Chinese), you need to make sure that the correct character encoding is provided so that the case is converted correctly.
Similar Functions