PHP strtoupper() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, strtoupper() converts every letter in a string to uppercase.

It returns a new string and does not change the original.

Syntax

Call strtoupper() with the values you need. Start with this line.

PHP
$upper = strtoupper($text);
CallWhat it does
strtoupper("Hello world")Returns "HELLO WORLD".
strtoupper("php 8.3")Returns "PHP 8.3". Digits and symbols stay the same.

Since PHP 8.2, strtoupper() only changes ASCII letters (a to z) and no longer depends on the locale. Use mb_strtoupper() for accented or non-English text.

Library declarations
PHP
strtoupper(string $string): string

Parameters

ParameterDescription
stringRequired. The input string.

Return Value

Return ValueDescription
stringThe string with all ASCII letters converted to uppercase.

PHP Examples

Example 1 — Convert Text to Uppercase

Pass a string and get an uppercase copy back.

PHP
<?php
$text = "Hello world";
$upper = strtoupper($text);

echo $upper, PHP_EOL;
echo $text, PHP_EOL;

How It Works

  1. Create a string. It contains lowercase letters.
  2. Call strtoupper(). It returns an uppercase copy.
  3. Print the copy. You see HELLO WORLD.
  4. Original is unchanged. $text keeps its case.

Example 2 — Only Letters Are Changed

Numbers, spaces, and punctuation pass through untouched.

PHP
<?php
echo strtoupper("php 8.3 is fun!"), PHP_EOL;
echo strtoupper("ALREADY UPPER"), PHP_EOL;
echo strtoupper("abc-123"), PHP_EOL;

How It Works

  1. Letters change. php becomes PHP.
  2. Numbers stay. 8.3 and 123 are unchanged.
  3. Symbols stay. ! and - are untouched.
  4. Already uppercase. The text is returned as is.

Example 3 — Build a Constant-Style Name

Combine str_replace() and strtoupper() to turn a label into a CONSTANT_NAME.

PHP
<?php
$key = "max upload size";
$const = strtoupper(str_replace(" ", "_", $key));

echo $const, PHP_EOL;

How It Works

  1. Start with a label. Words are separated by spaces.
  2. Replace spaces. str_replace() swaps each space for an underscore.
  3. Uppercase it. strtoupper() capitalizes every letter.
  4. Print the result. You get MAX_UPLOAD_SIZE.

Frequently Asked Questions

strtoupper() converts every letter in a string to uppercase and returns the new string.
string strtoupper(string $string). It takes one required argument.
No. It returns a new string. Save the result in a variable if you need it later.
Not properly. It only changes ASCII letters in PHP 8.2 and newer. Use mb_strtoupper() for multibyte text.
Use ucfirst() for the first letter of a string, or ucwords() for the first letter of each word.

Next: strtr()

strtr() translates characters or replaces whole substrings in a string.

strtr() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful