PHP Ctype
The Ctype extension provided the facility to check the data type of specific characters & strings like that It’s an integer or character, etc.
Example to check whether a given string is pure alphabetic or not
<?php
$strings = array('KjgWZC', 'arf12');
foreach ($strings as $testcase)
{
if (ctype_alpha($testcase))
{
echo "The string $testcase consists of all letters.\n";
}
else
{
echo "The string $testcase does not consist of all letters.\n";
}
}
?>
Output
The string KjgWZC consists of all letters.
The string arf12 does not consist of all letters.
Requirements
None besides functions from the standard C library are always available.
Installation
Beginning with PHP 4.2.0 these functions are enabled by default.
For older versions you have to configure and compile PHP with --enable-ctype.
You can disable ctype support with --disable-ctype.
The Windows version of PHP has built-in support for this extension.
You do not need to load any additional extensions in order to use these functions.
Run-time Configuration
This extension has no configuration directives defined in php.ini.
Resource Types
This extension has no resource types defined.
Predefined Constants
This extension has no constants defined.
Ctype Functions
-
ctype_alnum — Check for alphanumeric character(s)
-
ctype_alpha — Check for alphabetic character(s)
-
ctype_cntrl — Check for control character(s)
-
ctype_digit — Check for numeric character(s)
-
ctype_graph — Check for any printable character(s) except space
-
ctype_lower — Check for lowercase character(s)
-
ctype_print — Check for printable character(s)
-
ctype_punct — Check for any printable character which is not whitespace or an alphanumeric character
-
ctype_space — Check for whitespace character(s)
-
ctype_upper — Check for uppercase character(s)
-
ctype_xdigit — Check for character(s) representing a hexadecimal digit