Monday 26 August 2013

PHP Function ctype_alpha()

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.

Paramters

ParameterDescription
textRequired. 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.<br />";
 } else {
     echo "$testcase does not have all letters.<br />";
 }
}
?> 
This will produce following result:
KjgWZC consists of all letters.
arf12 does not have all letters.

No comments:

Post a Comment