The PHP CType Extension is a built-in extension of PHP4.2, note that the CType series functions have only one string type parameter, and they return a Boolean value.
Copy the Code code as follows:
$str = "0.1123";
Checks if all characters in a string are numeric
echo "Ctype_digit:". Ctype_digit ($STR); Empty
Detects if it is a numeric string and can be negative and fractional
echo "Is_numberic:". Is_numeric ($STR); 1
The difference between ctype_digit () and is_numberic () can be seen from the above.
Chinese translation
The CType function is a PHP built-in string body test function. Mainly have the following several
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)
Check if it is a character control character that contains only the class "\n\r\t"
Ctype_digit--Check for numeric character (s)
Check time 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 that contains only characters that can be printed (except for spaces)
Ctype_lower--Check for lowercase character (s)
Check if all characters are English letters and are lowercase
Ctype_print--Check for printable character (s)
Check if it is a string containing only the 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 printable character that contains only non-digits/characters/spaces
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)
Check if 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 binary string and can only include "0123456789abcdef"
There are examples of yo
We usually encounter some forms to do simple filtering, often less willing to write regular, and in the efficiency, the regular is also affecting the speed of PHP one of the reasons, so when you can not try the regular when try not to try regular. Fortunately PHP has taken this into account for us and provided me with the CType function. Here are some CType functions to make a brief introduction to the alternate:
1, Ctype_alnum-check for alphanumeric character (s) to check that the string contains only numbers or letters, equivalent to regular [a-za-z0-9]. There is a return value. On success, returns true with a failure of false;
[ copy code code as follows:
!--? php $strings = Array (' Abcd1zyz9 ', ' foo!# $bar ');
foreach ($strings as $testcase) {
if (Ctype_alnum ($testcase)) {
echo "the string $testcase consists of all L Etters or digits.\n "; \ \ Output The string abcd1zyz9 consists of all letters or digits.
} else {
echo "the string $testcase does not consist of all letters or digits.\n"; \ \ Output The string foo!# $bar do Es not consist of all letters or digits.
}
}
?>
2, Ctype_alpha-check for alphabetic character (s) checks that the string contains only letters. On success, returns true with a failure of false;
copy code code as follows:
!--? php $strings = Array (' KJGWZC ', ' arf12 ');
foreach ($strings as $testcase) {
if (Ctype_alpha ($testcase)) {
echo "the string $testcase consists of all L Etters.\n "; \ \ Output The string KJGWZC consists of all letters.
} else {
echo "the string $testcase does not consist of all letters.\n"; \ \ Output The string arf12 does not consist of all letters.
}
}
?>
3, Ctype_cntrl-check for control character (s) checks to see if the string contains only "\ n" \ r "\ T".
copy code code is as follows:
!--? PHP $ strings = Array (' string1 ' = ' = ' \n\r\t ', ' string2 ' = ' arf12 ');
foreach ($strings as $name = $testcase) {
if (Ctype_cntrl ($testcase)) {
echo "the string ' $name ' consist S of all Control characters.\n "; \ \ Output The string ' string1 ' consists of all control characters.
} else {
echo "the string ' $name ' does not consist of all control characters.\n"; \ The string ' string2 ' does n OT consist of all control characters.
}
}
?>
4, Ctype_digit-check for numeric character (s) checks if the string contains only numbers
Copy the Code code as follows:
$strings = Array (' 1820.20 ', ' 10002 ', ' wsl!12 ');
foreach ($strings as $testcase) {
if (Ctype_digit ($testcase)) {
echo "The string $testcase consists of all digits.\n";
} else {
echo "The string $testcase does not consist of all digits.\n";
}
}
?>
http://www.bkjia.com/PHPjc/744329.html www.bkjia.com true http://www.bkjia.com/PHPjc/744329.html techarticle The PHP CType Extension is a built-in extension of PHP4.2, note that the CType series functions have only one string type parameter, and they return a Boolean value. Copy the code code as follows: $str = "0.11 ...