Home >Backend Development >PHP Tutorial >PHP ctype function Chinese translation and examples_PHP tutorial
PHP Ctype extension is a built-in extension since PHP 4.2. Note that the Ctype series functions have only one string type parameter and they return Boolean values.
You can see the difference between ctype_digit() and is_numberic() from the above.
Chinese translation
The Ctype function is PHP’s built-in string body testing function. There are mainly the following types
ctype_alnum -- Check for alphanumeric character(s)
Check whether it only contains [A-Za-z0-9]
ctype_alpha -- Check for alphabetic character(s)
Check whether it only contains [A-Za-z]
ctype_cntrl -- Check for control character(s)
Check whether it only contains character control characters whose class is "nrt" and so on
ctype_digit -- Check for numeric character(s)
When checking, it is a string containing only numeric characters (0-9)
ctype_graph -- Check for any printable character(s) except space
Check whether it is a string containing only printable characters (except spaces)
ctype_lower -- Check for lowercase character(s)
Check whether all characters are English letters and all are lowercase
ctype_print -- Check for printable character(s)
Check whether it is a string containing only printable characters
ctype_punct -- Check for any printable character which is not whitespace or an alphanumeric character
Check whether it is a printable character that only contains non-digits/characters/spaces
ctype_space -- Check for whitespace character(s)
Check whether it only contains characters and spaces whose class is " " and spaces
ctype_upper -- Check for uppercase character(s)
Check whether all characters are English letters and all are uppercase
ctype_xdigit -- Check for character(s) representing a hexadecimal digit
Check whether it is a hexadecimal string, which can only include "0123456789abcdef"
There are examples
When we usually need to do simple filtering on some forms, we are often reluctant to write regular expressions. In terms of efficiency, regular expressions are also one of the reasons that affect the running speed of PHP, so try to use regular expressions when you can. Don't try regular rules. Fortunately, PHP has taken this into account for us and provided me with Ctype functions. Here is a brief introduction to some Ctype functions for reference:
1. ctype_alnum — Check for alphanumeric character(s) Check that the string only contains numbers or letters, which is equivalent to regular [A-Za-z0-9] . has a return value. Returns TRUE on success, FALSE on failure;
[
The code is as follows:
The code is as follows:
4、ctype_digit — Check for numeric character(s) 检查字符串中是否只包含数字