Tuesday, June 9, 2026
HomeLanguagesPHP | ctype_alpha() (Checks for alphabetic value)

PHP | ctype_alpha() (Checks for alphabetic value)

A ctype_alpha() function in PHP used to check all characters of a given string are alphabetic or not. If all characters are alphabetic then return True otherwise return False.

Syntax:

ctype_alpha($text)

Parameters Used:

  • $text :- It is a mandatory parameter which specifies the string.

Return Value:
It returns True if all characters of string are alphabets and a False on failure.

Examples:

Input  : neveropen
Output : Yes

Explanation : String (neveropen) contains only alphabets

Input  : GFG-GCET-2018
Output : No

Explanation : String contains Integer and special characters.
 
Note: Except string ,if you input anything then it will return FALSE.    

Below programs illustrate the ctype_alpha() function.

Program: 1




<?php
// PHP program to check given string is 
// all characters -alphabetic
  
$string = 'neveropen';
  
    if ( ctype_alpha($string)) 
      
        echo "Yes\n";
    else 
        echo "No\n";
?>


Output:

Yes

Program : 2 Drive a code ctype_alpha() function where input an array of string which contains integers and special characters.




<?php
// PHP program to check given string is 
// all characters are alphabetic
  
$strings = array(
    'GFG',
    'GFG space',
    '@@##-- /',
    '789543',
    '\n'
);
  
// Checking above given strings 
// by used of ctype_alpha() function .
foreach ($strings as $test) {
      
    if (ctype_alpha($test))
        echo "Yes\n";
    else
        echo "No\n";
      
}
  
?>


Output:

Yes
No
No
No
No

Related Article: PHP | ctype_alnum() (Check for Alphanumeric)
Reference:
http://php.net/manual/en/function.ctype-alpha.php

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6895 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7018 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS