ctype_digit

(PHP 4 >= 4.0.4, PHP 5, PHP 7)

ctype_digit锟斤拷锟斤拷锟斤拷锟街硷拷锟�

说锟斤拷

ctype_digit ( string $text ) : bool

锟斤拷锟斤拷峁╋拷锟� string 锟斤拷 text 锟斤拷锟斤拷锟斤拷址锟斤拷遣锟斤拷嵌锟斤拷锟斤拷锟斤拷帧锟�

锟斤拷锟斤拷

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锟街凤拷). 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟结被锟斤拷锟斤拷为锟斤拷值锟斤拷应锟斤拷十锟斤拷锟斤拷锟街凤拷锟斤拷.

锟轿硷拷

  • ctype_alnum() - 锟斤拷锟斤拷母锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟�
  • ctype_xdigit() - 锟斤拷锟斤拷址锟斤拷锟斤拷欠锟街伙拷锟斤拷锟绞拷锟斤拷锟斤拷锟斤拷址锟�
  • is_numeric() - 锟斤拷锟斤拷锟斤拷锟角凤拷为锟斤拷锟街伙拷锟斤拷锟斤拷锟街凤拷锟斤拷
  • is_int() - 锟斤拷锟斤拷锟斤拷锟角凤拷锟斤拷锟斤拷锟斤拷
  • is_string() - 锟斤拷锟斤拷锟斤拷锟角凤拷锟斤拷锟街凤拷锟斤拷