ctype_digit

ctype_digit是PHP的函式,主要功能是檢測字元串中的字元是否都是數字,負數和小數會檢測不通過。 注意,參數一定要是字元串,如果不是字元串,則會返回0/FASLE。

基本介紹

  • 外文名:ctype_digit
  • 說明:boolctype_digit( string text )
  • 參數:text The tested string.
  • 類型:函式
ctype_digit,說明,參數,返回值,範例,

ctype_digit

(PHP 4 >= 4.0.4, PHP 5)
ctype_digit -- Check for numeric character(s)

說明

bool ctype_digit ( string text )
Checks if all of the characters in the provided string, text, are numerical.

參數

text The tested string.

返回值

Returns TRUE if every character in text is a decimal digit, FALSE otherwise.

範例

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 consists of all digits. The string 10002 consists of all digits. The string wsl!12 does not consists of all digits.

相關詞條

熱門詞條

聯絡我們