(PHP 4 >= 4.0.4, PHP 5, PHP 7)
ctype_digit — 做纯数字检测
text需要被测试的字符串。
   如果 text 字符串是一个十进制数字,就返回 TRUE ;反之就返回 FALSE 。
  
| 版本 | 说明 | 
|---|---|
| 5.1.0 | 在 PHP 5.1.0 之前,当 text是一个空字符串的时候,该函数将返回TRUE。 | 
Example #1 一个 ctype_digit() 例子
<?php
$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";
    }
}
?>
以上例程会输出:
The string 1820.20 does not consist of all digits. The string 10002 consists of all digits. The string wsl!12 does not consist of all digits.
Example #2 一个通过 ctype_digit() 来比对字符和整数的例子。
<?php
$numeric_string = '42';
$integer        = 42;
ctype_digit($numeric_string);  // true
ctype_digit($integer);         // false (ASCII 42 is the * character)
is_numeric($numeric_string);   // true
is_numeric($integer);          // true
?>
Note:
这个函数的参数要求是一个 string 这一点是非常有用的,因此当你传入一个 integer 的参数也许不能得到期望的结果。然后,同样需要注意HTML表单将会返回数字字符串而不是一个整型。 看下手册的 types 章节。
Note:
如果给出一个 -128 到 255 之间(含)的整数, 将会被解释为该值对应的ASCII字符 (负值将加上 256 以支持扩展ASCII字符). 其它整数将会被解释为该值对应的十进制字符串.