Content · Programming · PHP

PHP ctype_upper() Function: Usage and Examples

Learn how PHP ctype_upper works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Checks whether all characters are uppercase letters.

What Is ctype_upper() in PHP?

Checks whether all characters are uppercase letters.

Its syntax is:

ctype_upper(mixed $text): bool

Parameters:

  • $text — Accepted as mixed; required argument.

Return type: bool. An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.

Availability: Requires the ctype extension, normally bundled with PHP.

Example 1: Basic Usage

<?php

var_dump(ctype_upper("READY"));

Output:

bool(true)

An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.

Example 2: A Different Input

<?php

var_dump(ctype_upper("Ready"));

Output:

bool(false)

An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.

Practical Example: Applying It in a Program

<?php

$samples = ["A1", "AB", "12", "A-1"]; foreach ($samples as $sample) { echo $sample . ": " . (ctype_upper($sample) ? "yes" : "no") . PHP_EOL; }

Output:

A1: no
AB: yes
12: no
A-1: no

An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.

Important Behavior and Edge Cases

  • Key behavior: An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.
  • Environment: Requires the ctype extension, normally bundled with PHP.

Comparison With Related Functions

FunctionPurpose
ctype_upper()Checks whether all characters are uppercase letters.
preg_match()preg_match() evaluates a regular-expression pattern; ctype_* functions test every byte against a predefined character class.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: An empty string returns falseAn empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.

Key Takeaways

  • Checks whether all characters are uppercase letters.
  • An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.
  • Requires the ctype extension, normally bundled with PHP.

Summary: An empty string returns false. These functions examine bytes and locale classification, not full Unicode character properties.

Share this resourceSend this page to someone who may find it useful.