Skip to content
Tutorials Center
My learning

Topics

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
<?php
echo mb_strtoupper("école");  // ÉCOLE

Try it

PHP Unicode uppercase

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.

PHP Length changes and shouting a title

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

PHP
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. ß becomes SS, 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() with MB_CASE_FOLD is better.
  • Titles and names: MB_CASE_TITLE in mb_convert_case() capitalizes the first letter of each word, the multibyte counterpart of ucwords().
  • 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(); combine mb_substr() and mb_strtoupper(). PHP 8.4 added mb_ucfirst() and mb_lcfirst().
  • It needs the mbstring extension, which most hosts enable, but it is not part of the PHP core.