strtoupper()
The strtoupper() function in PHP is used to convert all the lowercase letters in a string to uppercase. This function is particularly useful when working with
Introduction
strtoupper() converts every lowercase letter in a string to uppercase and returns the result. The original string is left unchanged — like all PHP string functions, strtoupper() returns a new string rather than modifying its argument in place.
You reach for it whenever you need case-insensitive output or comparison: normalizing country codes (us → US), shouting a heading, or comparing two strings without caring about case. This page covers the syntax, the all-important multibyte caveat, and the related functions you'll often use alongside it.
Syntax
strtoupper(string $string): string| Part | Description |
|---|---|
$string | The input string. Required. |
| Return | A copy of $string with every ASCII lowercase letter (a–z) converted to uppercase. Non-letter characters are returned untouched. |
A basic example
Digits, spaces, and punctuation (!) pass through unchanged — only the letters are upcased. Note that $string itself still holds "Hello World!"; the converted text lives in $uppercase.
Case-insensitive comparison
A common use is comparing user input without worrying about how it was typed. Uppercase both sides, then compare:
<?php
$input = "Yes";
if (strtoupper($input) === "YES") {
echo "Confirmed";
} else {
echo "Not confirmed";
}
// ConfirmedThis is why strtoupper() (and its counterpart strtolower()) show up so often in form-handling and routing code.
The multibyte gotcha
strtoupper() is byte-based and locale-unaware for anything outside plain ASCII. It only knows how to upcase a–z. Accented and non-Latin letters are left as-is:
<?php
echo strtoupper("café"); // CAFé — the é is not convertedFor Unicode text (UTF-8 strings with accents, ñ, Cyrillic, Greek, etc.) use mb_strtoupper(), which understands character encodings:
<?php
echo mb_strtoupper("café", "UTF-8"); // CAFÉRule of thumb: ASCII-only data (codes, slugs, English-only labels) → strtoupper(). Anything that might contain international characters → mb_strtoupper().
Related functions
strtolower()— the inverse: converts uppercase letters to lowercase.ucfirst()— uppercases only the first character of a string.ucwords()— uppercases the first character of each word.
Summary
strtoupper() returns a new, fully uppercase copy of an ASCII string and is handy for normalizing data and case-insensitive comparisons. For text that may contain non-ASCII characters, prefer mb_strtoupper() so accented and non-Latin letters are converted correctly.