PHP | ctype_alpha() (Checks for alphabetic value)
Last Updated :
07 Jun, 2018
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
<?php
$string = 'GeeksforGeeks' ;
if ( ctype_alpha( $string ))
echo "Yes\n" ;
else
echo "No\n" ;
?>
|
Program : 2 Drive a code ctype_alpha() function where input an array of string which contains integers and special characters.
<?php
$strings = array (
'GFG' ,
'GFG space' ,
'@@##-- /' ,
'789543' ,
'\n'
);
foreach ( $strings as $test ) {
if (ctype_alpha( $test ))
echo "Yes\n" ;
else
echo "No\n" ;
}
?>
|
Related Article: PHP | ctype_alnum() (Check for Alphanumeric)
Reference:
http://php.net/manual/en/function.ctype-alpha.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...