Skip to content
Tutorials Center
My learning

Topics

PHP Reference · String Functions

PHP strtoupper() function

Reference for PHP strtoupper(): convert a string to uppercase, why only ASCII letters change since PHP 8.2, and when to switch to mb_strtoupper().

strtoupper() returns a copy of a string with every lowercase ASCII letter (a to z) converted to uppercase. Digits, punctuation and non-ASCII bytes stay as they are.

Since PHP 8.2 the function ignores the locale and handles ASCII only. To uppercase accented letters in UTF-8 text, use mb_strtoupper(). The result for ß is a good example of why: the multibyte version turns it into SS.

PHP
<?php
echo strtoupper("Hello world");  // HELLO WORLD

Try it

PHP Uppercasing text

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 Why mb_strtoupper() exists

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
strtoupper(string $string): string
Name Description
$string The input string.

Return value: the uppercase string.

Usage notes

  • ASCII only since PHP 8.2; before that it depended on setlocale(LC_CTYPE). Do not rely on locale tricks.
  • Multibyte letters such as é, ж or ß are left unchanged. Use mb_strtoupper().
  • Same length. Because only single bytes change, the result has exactly the same byte length as the input; the multibyte version can change the length (ß becomes SS).
  • Case-insensitive comparison: use strcasecmp() rather than converting both strings.
  • Only the first letter: see ucfirst() and ucwords().
  • Do not use it for security decisions on user input such as file extensions without also validating the content.