The usage of the Ctype function in php is described in detail. The usage of the Ctype function in php is described in detail. this document analyzes the usage of the Ctype function in php. Share it with you for your reference. The specific analysis is as follows: the Ctype function is the Php Ctype extension function. It provides a detailed explanation of the usage of the Ctype function in php.
This document analyzes the usage of the Ctype function in php. Share it with you for your reference. The specific analysis is as follows:
The Ctype function is Php's Ctype extension function. It provides a set of functions to verify whether the characters in the string are in the correct format, here we will mainly introduce the syntax of these string verification functions, what special functions are available, and how to verify them.
The Ctype function is a built-in PHP string body test function. It mainly includes the following types:
Ctype_alnum -- Check for alphanumeric character (s): checks 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 such as "nrt ".
Ctype_digit -- Check for numeric character (s): Check whether a string contains only numbers (0-9)
Ctype_graph -- Check for any printable character (s) character t space: Check whether the string contains only printable characters (except spaces)
Ctype_lower -- Check for lowercase character (s): Check whether all characters are English letters and all characters are in lowercase.
Ctype_print -- Check for printable character (s): checks whether a string contains only printable characters.
Ctype_punct -- Check for any printable character which is not whitespace or an alphanumeric character: Check whether only printable characters including non-numbers, characters, and spaces are allowed.
Ctype_space -- Check for whitespace character (s): Check whether it only contains characters and spaces such "".
Ctype_upper -- Check for uppercase character (s): Check whether all characters are English letters and uppercase letters
Ctype_xdigit -- Check for character (s) representing a hexadecimal digit: Check whether it is a hexadecimal string and can only contain "0123456789abcdef"
How to use them, directly go to the code:
The code is as follows:
$ Str1 = 'azxc1234'; // true
$ Str2 = '2014 # taobao'; // false
If (ctype_alnum ($ string )){
Echo "This string totally works ";
}
Else {
Echo "And this one not so much ";
}
Note: If the first empty string is passed, false is returned after php5.1, but true is returned in earlier versions.
The code is as follows:
The code is as follows:
$ Integer = 42;
Ctype_digit ($ integer); // false
Ctype_digit (string) $ integer); // true
Conclusion: the same operation may have different methods when using PHP. it is important to select an appropriate method. In PHP, there are two types of string-type functions: ctype _ * and is _ *. in actual applications, they use the is _ * series of functions, of course, in addition to these methods, we can also use regular expressions for judgment, which is more powerful, but using PHP built-in functions can better reduce the error rate.
In this article, we analyze the usage of the Ctype function in php. Share it with you for your reference. The specific analysis is as follows: the Ctype function is a set of Php Ctype extension functions...