The CType function is a string-body-testing function built into PHP. Mainly has the following several
Ctype_alnum--Check for alphanumeric character (s)
Detect if it contains only [a-za-z0-9]
Ctype_alpha--Check for alphabetic character (s)
Detect if it contains only [a-za-z]
Ctype_cntrl--Check for control character (s)
Check whether it is a character control character that contains only the class is "NRT"
Ctype_digit--Check for numeric character (s)
The check is a string containing only numeric characters (0-9)
Ctype_graph--Check for any printable character (s) except spaces
Check whether it is a string that contains only characters that can be printed (except spaces)
Ctype_lower--Check for lowercase character (s)
Check to see if all the characters are in English letters and are all lowercase
Ctype_print--Check for printable character (s)
Check if it is a string that contains only characters that can be printed
CTYPE_PUNCT--Check for any printable character which are not whitespace or a alphanumeric
Check for printable characters that contain only non-numeric/character/space
Ctype_space--Check for whitespace character (s)
Check for characters and spaces that contain only the class as ""
Ctype_upper--Check for uppercase character (s)
Check that all characters are in English letters and are all uppercase
Ctype_xdigit--Check for character (s) representing a hexadecimal digit
Check if it is a 16-in string and can only include "0123456789abcdef"
If you use them
Nonsense not much to say directly on the code:
The code is as follows |
Copy Code |
<?php $str 1 = ' Azxc1234 ';//true $str 2 = ' 123#axy ';//false if (Ctype_alnum ($string)) { echo "This string totally works"; } else { echo "And this one isn't so much"; } |
Note: If you pass the first empty string, it returns false after php5.1, but the earlier version returns True.
Just make sure that the argument passed to the function is a string and there is no problem.
The code is as follows |
Copy Code |
<?php $integer = 42; Ctype_digit ($integer); False Ctype_digit ((string) $integer); True |
Conclusion
In the process of using PHP, the same operation may have different methods, it is obviously important to choose a suitable method. There are two types of functions that judge string types in PHP, ctype_* and is_* they is_* this series of functions in a practical application. Of course we can choose to use regular expressions to make judgments and be more powerful in addition to these options, but using PHP's built-in functions can be a better way to reduce error rates.