PHP - Function ctype_alpha()


Advertisements


Syntax

ctype_alpha ( $text );

Definition and Usage

Checks if all of the characters in the provided string, text, are alphabetic. In the standard C locale letters are just [A-Za-z] and ctype_alpha() is equivalent to (ctype_upper($text) || ctype_lower($text)) if $text is just a single character.

Parameters

Parameter Description
text Required. The tested string.

Return Value

Returns TRUE if every character in text is a letter, FALSE otherwise.

Example

Try out following example −

<?php
   $strings = array('KjgWZC', 'arf12');
   
   foreach ($strings as $testcase) {
      if (ctype_alpha($testcase)) {
         echo "$testcase consists of all letters. \n";
      }
      else
      {
         echo "$testcase does not have all letters. \n";
      }
   }
?> 

This will produce the following result −

KjgWZC consists of all letters.
arf12 does not have all letters.

php_function_reference.htm

Advertisements