ctype_digit
PHP ctype_digit()函数 (PHP ctype_digit() function)
ctype_digit() function is a character type (CType) function in PHP, it is used to check whether a given string contains only digits or not.
ctype_digit()函数是PHP中的字符类型(CType)函数,用于检查给定的字符串是否仅包含数字。
It returns true – if the string contains only digits (0...9), else it returns false.
它返回true -如果字符串仅包含数字(0 ... 9),否则返回FALSE。
Syntax:
句法:
ctype_digit(string) : bool
Example:
例:
Input: "1234"
Output: true
Input: "Hello123"
Output: false
Input: "[email protected]&a"
Output: false
PHP code:
PHP代码:
<?php
$str = "123456";
if(ctype_digit($str))
echo ("$str contains only digits.\n");
else
echo ("$str does not contain only digits.\n");
$str = "123.456";
if(ctype_digit($str))
echo ("$str contains only digits.\n");
else
echo ("$str does not contain only digits.\n");
$str = "Hello world123";
if(ctype_digit($str))
echo ("$str contains only digits.\n");
else
echo ("$str does not contain only digits.\n");
$str = "[email protected]&a";
if(ctype_digit($str))
echo ("$str contains only digits.\n");
else
echo ("$str does not contain only digits.\n");
?>
Output
输出量
123456 contains only digits.
123.456 does not contain only digits.
Hello world123 does not contain only digits.
[email protected]&a does not contain only digits.
翻译自: https://www.includehelp.com/php/ctype_digit-function-with-example.aspx
ctype_digit