W3docs

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 (usUS), 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
PartDescription
$stringThe input string. Required.
ReturnA copy of $string with every ASCII lowercase letter (az) converted to uppercase. Non-letter characters are returned untouched.

A basic example

php— editable, runs on the server

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. Upper­case both sides, then compare:

<?php

$input = "Yes";

if (strtoupper($input) === "YES") {
    echo "Confirmed";
} else {
    echo "Not confirmed";
}
// Confirmed

This 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 az. Accented and non-Latin letters are left as-is:

<?php

echo strtoupper("café"); // CAFé  — the é is not converted

For 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().

  • 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.

Practice

Practice
What does the PHP function strtoupper do?
What does the PHP function strtoupper do?
Was this page helpful?