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  : GeeksforGeeks
Output : Yes

Explanation : String (GeeksforGeeks) 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

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Yes

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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";
      
}
  
?>

chevron_right


Output:

Yes
No
No
No
No

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.