Content · Programming · PHP

PHP ctype_alpha() Function: Usage and Examples

Learn how PHP ctype_alpha 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 letters under the current locale.

What Is ctype_alpha() in PHP?

Checks whether all characters are letters under the current locale.

Its syntax is:

ctype_alpha(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_alpha("OnlyLetters"));

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_alpha("Name7"));

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_alpha($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_alpha()Checks whether all characters are letters under the current locale.
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 letters under the current locale.
  • 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.