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"; ?> |
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";       }   ?> |
Yes No No No No
Related Article: PHP | ctype_alnum() (Check for Alphanumeric)
Reference:
http://php.net/manual/en/function.ctype-alpha.php
