This article mainly introduces the PHP CType function Chinese translation and the example, the correlation function example lists several, needs the friend to be possible to refer to under
PHP CType Extensions are extensions that PHP4.2 started, and note that CType series functions have only one string type parameter that returns a Boolean value. Code as follows: $str = "0.1123"; Checks whether all characters of the string are numeric echo "Ctype_digit:". Ctype_digit ($STR); ////detection is a numeric string that can be negative and decimal echo "Is_numberic:". Is_numeric ($STR); 1 From above you can see the difference between ctype_digit () and Is_numberic (). Chinese translation CType function is a built-in string body measurement function in PHP. There are several main ctype_alnum-check for alphanumeric character (s) detect whether it contains only [a-za-z0-9] Ctype_alpha--Check for Alph Abetic character (s) detects whether it contains only [a-za-z] Ctype_cntrl--Check for control character (s) checks whether it is a character-controlled character that contains only the class is "NRT" Ctype_digit--Check for numeric character (s) checking is a string containing only numeric characters (0-9) Ctype_graph--check for any printable charact ER (s) except space checks whether it is a string ctype_lower that contains only characters that can be printed (except spaces)-Check for lowercase character (s) checks whether all characters are English letters and All lowercase ctype_print-check for printable character (s) checks whether it is a string that contains only characters that can be printed out CTYPE_PUNCT-check for any PR intable character which isn't whitespace or an alphanumeric charaCter Check if it is a printable character ctype_space that contains only non-numeric/character/space-check for whitespace character (s) checks for characters and spaces that contain only the class as "" CType _upper-Check for uppercase character (s) checks to see if all characters are in English letters and are all uppercase Ctype_xdigit-check for character (s) represent ing a hexadecimal digit check whether it is a 16 binary string, only include "0123456789abcdef" There are examples of yo we usually don't like to write regular when we have to do simple filtering on some forms. And in efficiency, is also the impact of PHP running speed One of the reasons, so can not try the regular time as far as possible without trial. Luckily, PHP has given this to us and provided me with the CType function. Some CType functions are briefly described below to spare: 1, Ctype_alnum-check for alphanumeric character (s) Check that the string contains only numbers or letters, equivalent to regular [a-za-z0-9]. has a return value. Returns true on success and false; [code: <?php $strings = Array (' Abcd1zyz9 ', ' foo!# $bar '); foreach ($strings as $TESTC ASE) { if (Ctype_alnum ($testcase)) { echo "The string $testcase Co Nsists of all letters 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 "; The output of the string foo!# $bar does not consist to all letters or digits. } } ?> 2, Ctype_alpha-check for alphabetic character (s) Check string Contains only the letters. Returns true on success and false; code as follows: <?php $strings = Array (' KJGWZC ', ' arf12 '); foreach ($strings as $testcase) { if (Ctype_alpha ($testcase)) { &N Bsp echo "The string $testcase consists of all LETTERS.N"; Output The string KJGWZC consists of all letters. } else { echo "The string $testcase does not consist of S.N "; <span style=" White-space:pre "> </span> output of the string arf12 does not consist to all letters. } } ?> 3, Ctype_cntrl-check for control character (s) check Check if the string contains only control characters such as "' N ' r '". Code as follows: <?php $strings = Array (' string1 ' => "NRT", ' string2 ' => ' arf12 '); foreach ($strings as $name => $testcase) { if (Ctype_cntrl ($testcase)) { &nbs P echo "The string ' $name ' consists of all control CHARACTERS.N"; Output the string ' string1 ' consists of all control characters. } else { echo "The string ' $name ' does not consist to all control CHARACTERS.N "; The string ' string2 ' does not consist to all control characters. } } ?> 4, Ctype_digit-check for numeric character (s) Check word Whether the string contains only the number code is as follows: <?php $strings = Array (' 1820.20 ', ' 10002 ', ' wsl!12 '); foreach ($strings as $testcase) { if (Ctype_digit ($testcase)) { &N Bsp echo "The string $testcase consists of all DIGITS.N"; } else { echo "The StriNg $testcase does not consist to all DIGITS.N "; } } ?>