(PHP 4 >= 4.0.4, PHP 5, PHP 7)
ctype_digit — 锟斤拷锟斤拷锟斤拷锟街硷拷锟�
text
锟斤拷要锟斤拷锟斤拷锟皆碉拷锟街凤拷锟斤拷锟斤拷
锟斤拷锟� text
锟街凤拷锟斤拷锟斤拷一锟斤拷十锟斤拷锟斤拷锟斤拷锟街o拷锟酵凤拷锟斤拷 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 锟斤拷一锟斤拷锟角非筹拷锟斤拷锟矫的o拷锟斤拷说锟斤拷愦拷锟揭伙拷锟� integer 锟侥诧拷锟斤拷也锟斤拷锟杰得碉拷锟斤拷锟斤拷锟侥斤拷锟斤拷锟饺伙拷锟酵拷锟斤拷锟揭拷锟紿TML锟斤拷锟斤拷锟结返锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟酵★拷 锟斤拷锟斤拷锟街诧拷锟� types 锟铰节★拷
Note:
锟斤拷锟斤拷锟斤拷锟揭伙拷锟� -128 锟斤拷 255 之锟斤拷(锟斤拷)锟斤拷锟斤拷锟斤拷, 锟斤拷锟结被锟斤拷锟斤拷为锟斤拷值锟斤拷应锟斤拷ASCII锟街凤拷 (锟斤拷值锟斤拷锟斤拷锟斤拷 256 锟斤拷支锟斤拷锟斤拷展ASCII锟街凤拷). 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟结被锟斤拷锟斤拷为锟斤拷值锟斤拷应锟斤拷十锟斤拷锟斤拷锟街凤拷锟斤拷.