The character type functions are Boolean functions used to check the type of the characters on a string. They return true if all the characters are ofthe type specified by the function. These functions are useful for example if you want to validate a new password submitted by a user. You can check with them that the password submitted do not contains any special character.
The following example shows the use of these functions
|
<?php
$para="There are 10 players on each team.";
print ctype_alnum($para)."<br>"; //returns 1 (true)
print ctype_alpha($para)."<br>"; //returns 0 (false)
$myhex="AF12"
print ctype_xdigit($myhex)."<br>"; //returns 1 (true)
?> |
The table bellow list these functions:
Function | Type of characters checked | Example |
ctype_alnum | alphanumeric | 0-9 A-Z a-z |
ctype_alpha | alphabetic | A-Z a-z |
ctype_cntrl | control | Tab, esc, etc |
ctype_digit | numeric | 0-9 |
ctype_graph | any printable character except space | 0-9 A-Z a-z |
ctype_lower | lowercase | a-z |
ctype_print | printable | 0-9 A-Z a-z space |
ctype_punct | any printable character which is not whitespace or an alphanumeric character | Nn 0-9 A-Z a-z space |
ctype_space | whitespace | blank character , tab, vertical tab, etc. |
ctype_upper | uppercase | A-Z |
ctype_xdigit | representing a hexadecimal digit | Decimal digits and characters frm A-F and a-f |