You should use ctype_digitfor this:
function integer($str) {
return ctype_digit($str) ? $str : false;
}
Or use filter_varwithFILTER_VALIDATE_INT
function integer($str) {
return filter_var($str, FILTER_VALIDATE_INT, array(
'options' => array('min_range' => 0),
'flags' => FILTER_FLAG_ALLOW_OCTAL
));
}
NikiC source
share