- preg_match: documentation ( source)
<?php
function check_int($i) {
if (preg_match('[^0-9]', $i)) {
return 0;
} else {
return 1;
}
}
function check_int1($i) {
return (strval((int)$i) === strval($i));
}
echo check_int1(10) ? "It's an int" : "It's not an int";