PHP Reference · String Functions
PHP mb_strtoupper() function
Reference for PHP mb_strtoupper(): convert multibyte UTF-8 text to uppercase with full Unicode case mapping, encodings, and how it differs from strtoupper().
mb_strtoupper() converts a string to uppercase according to Unicode rules and a given character encoding. Unlike strtoupper(), which only changes the ASCII letters a to z, it knows accented letters, Greek, Cyrillic and many other scripts.
The function belongs to the mbstring extension. Since PHP 7.3 it uses full case mapping, so one character can become several: the German sharp s ß turns into SS, which makes the result longer than the input.
<?php echo mb_strtoupper("école"); // ÉCOLE
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input · what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input · what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.
Syntax
mb_strtoupper(string $string, ?string $encoding = null): string
| Name | Description |
|---|---|
$string |
The string to convert. |
$encoding |
A character encoding name such as "UTF-8". null uses the internal encoding, which is UTF-8 by default. |
Return value: the uppercase string.
Errors: throws a ValueError if $encoding is not a supported encoding name.
Usage notes
- Use it for any text that may contain non-ASCII letters.
strtoupper()works byte by byte and would leaveéuntouched (since PHP 8.2 it is also locale-independent). - The result can be longer.
ßbecomesSS, so never assume the same character count after conversion. - Use it for case-insensitive comparison only with care. Lowercasing with
mb_strtolower()is the usual normalization step; for strict Unicode caseless matching,mb_convert_case()withMB_CASE_FOLDis better. - Titles and names:
MB_CASE_TITLEinmb_convert_case()capitalizes the first letter of each word, the multibyte counterpart ofucwords(). - Always check your input encoding. Invalid UTF-8 bytes are replaced or mishandled; validate with
mb_check_encoding()for untrusted input. - First letter only: before PHP 8.4 there is no
mb_ucfirst(); combinemb_substr()andmb_strtoupper(). PHP 8.4 addedmb_ucfirst()andmb_lcfirst(). - It needs the
mbstringextension, which most hosts enable, but it is not part of the PHP core.