Computer >> Computer tutorials >  >> Programming >> PHP

ctype_alpha() function in PHP


The ctype_alpha() function check for alphabetic character(s). It returns TRUE if every character in text is a letter, FALSE otherwise.

Syntax

ctype_alpha ( $str );

Parameters

  • str − The tested string

Return

The ctype_alpha() function returns TRUE if every character in text is a letter, FALSE otherwise.

Example

The following is an example −

<?php
   $str = array('demo', 'de967demo');

   foreach ($str as $a) {
      if (ctype_alpha($a)) {
         echo "$a consists of all letters. \n";
      } else {
         echo "$a does not have all letters. \n";
      }
   }
?>

Output

The following is the output −

demo consists of all letters.
de967demo does not have all letters.