Detailed explanation of the usage of Ctype function in php, detailed explanation of phpctype function_PHP tutorial

WBOY
Release: 2016-07-13 10:12:09
Original
1022 people have browsed it

Detailed explanation of the usage of Ctype function in php, detailed explanation of phpctype function

This article analyzes the usage of Ctype functions in php with examples. Share it with everyone for your reference. The specific analysis is as follows:

The Ctype function is the Ctype extension function of Php. It provides a set of functions for verifying whether the characters in the string are in the correct format. Here we mainly introduce the syntax of these string verification functions and what special functions there are. How to verify etc.

Ctype function is PHP’s built-in string body measurement function, which mainly includes 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"

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 such as " "

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"

How to use them, go directly to the code:


Copy code The code is as follows:
$str1 = 'Azxc1234';//true
$str2 = '123#Axy';//false
if (ctype_alnum($string)) {
echo "This string totally works";
}
else {
echo "And this one not so much";
}

Note: If you pass the first empty string, false will be returned after php5.1, but early versions will return true. As long as you make sure the parameter passed to the function is a string, there will be no problem. The code is as follows:


Copy code The code is as follows:
$integer = 42;
ctype_digit($integer); // false
ctype_digit((string)$integer); // true
Conclusion: In the process of using PHP, there may be different methods for the same operation, and it is obviously important to choose an appropriate method. There are two types of functions to determine the string type in PHP, ctype_* and is_*. In actual applications, the is_* series of functions are more commonly used. Of course, in addition to these methods, we can also choose to use regular expressions. Make judgments and is more powerful, but using PHP's built-in functions can better reduce the error rate.
I hope this article will be helpful to everyone’s PHP programming design.

http://www.bkjia.com/PHPjc/924541.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/924541.htmlTechArticleDetailed explanation of the usage of Ctype function in php, Detailed explanation of phpctype function. This article analyzes the usage of Ctype function in php with examples. Share it with everyone for your reference. The specific analysis is as follows: Ctype function is the Ctype extension of Php...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!