CType function usage in PHP
This paper analyzes the usage of CType function in PHP. Share to everyone for your reference. The specific analysis is as follows:
The CType function is a php CType extension function that provides a set of functions to check if the characters in the string are the correct format, here we mainly introduce the syntax of these string validation functions, what special functions, how to verify, and so on.
The CType function is a PHP built-in string-body function, mainly in the following ways:
Ctype_alnum-Check for alphanumeric character (s): detects if it contains only [a-za-z0-9]
Ctype_alpha-Check for alphabetic character (s): detects if it contains only [a-za-z]
Ctype_cntrl-Check for control character (s): Checks if it is a character control character that contains only the class "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 space: Check if it is a string containing only characters that can be printed (except spaces)
Ctype_lower-Check for lowercase character (s): Checks if all characters are English letters and are lowercase
Ctype_print-Check for printable character (s): Checks if it is a string containing only characters that can be printed
CTYPE_PUNCT--Check for any printable character which are not whitespace or an alphanumeric character: check if it is a non-numeric/character/space-only Print out the characters
Ctype_space--Check for whitespace character (s): Check if it is a character and space that contains only the class ""
Ctype_upper-Check for uppercase character (s): Checks if all characters are in English letters and are in uppercase
Ctype_xdigit--Check for character (s) representing a hexadecimal digit: check if it is a 16 binary string and can only include "0123456789abcdef"
How to use them, directly on the code:
The code is as follows:
$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 the first empty string is passed, it returns false after php5.1, but the earlier version is return true.
As long as you ensure that the argument passed to the function is a string, there is no problem with the code as follows:
The code is as follows:
$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 for judging string types in PHP, ctype_* and is_* they is_* this series of functions in practical applications, and of course we can choose to use regular expressions to make judgments, and more powerful, But using PHP's built-in functions can be a better way to reduce the error rate.
http://www.bkjia.com/PHPjc/926228.html www.bkjia.com true http://www.bkjia.com/PHPjc/926228.html techarticle CType Function usage in PHP This article analyzes the usage of CType function in PHP. Share to everyone for your reference. The specific analysis is as follows: The CType function is a set of PHP CType extension functions that provide ...