ctype_digit
Description
The ctype_digit of Ctype for PHP checks for numeric character(s).
Syntax
ctype_digit(
mixed $text
): boolParameters
text
The tested string.
NOTE: If an integer between -128 and 255 inclusive is provided, it is interpreted as the ASCII value of a single character (negative values have 256 added in order to allow characters in the Extended ASCII range). Any other integer is interpreted as a string containing the decimal digits of the integer.
Return
Returns true if every character in the string text is a decimal digit, false otherwise.
When called with an empty string the result will always be false.
Examples
1 · text · empty
<? $text = ""; $return = ctype_digit($text); var_export($return);
false
2 · text · numeric
<? $text = "0123456789"; $return = ctype_digit($text); var_export($return);
true
3 · text · integer
<?
for($i = -128; $i <= 255; ++$i)
{
$return = ctype_digit($i);
if($return)
{
echo "$i: ". chr($i). PHP_EOL;
}
}
48: 0 49: 1 50: 2 51: 3 52: 4 53: 5 54: 6 55: 7 56: 8 57: 9