My function:
<?php
function isDigital($var){
return (!empty($var) && (is_string($var) || is_int($var)) && ctype_digit((string) $var));
}
?>
It returns true only when given positive integer or string that contains only digits.
![]() | ctype_digit说明bool ctype_digit ( string text )Checks if all of the characters in the provided string, text, are numerical. 范例
![]()
GamblerZG
13-Sep-2005 02:30
My function:
crimson at technologist dot com
12-Sep-2005 06:05
In PHP 4.3.11 (not sure about other versions), this function can provide erratic behavior. Though we normally expect automatic type casting to do the work for us, in these ctype functions, you must do it yourself!
info at challengia dot com
12-Jan-2005 06:25
Note : ctype_digit(1) return false. So if you use it against an unknown type, cast you var to string first -- ctype_digit((string)$myvar).
| ![]() |