Open In App

PHP | ctype_alpha() (Checks for alphabetic value)

Last Updated : 07 Jun, 2018
Improve
Improve
Like Article
Like
Save
Share
Report

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
// PHP program to check given string is 
// all characters -alphabetic
  
$string = 'GeeksforGeeks';
  
    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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads