Altrimenti potresti sfruttare anche la preg_match
oppure proprio la funzione is_numericCodice PHP:$pattern = "/^([0-9]+)$/";
if(preg_match($pattern,$string)) {
echo 'intero';
} else {
echo 'non intero';
}
Codice PHP:function isInt ($x=0){
return (is_numeric($x) ? intval($x) == $x : false);
}
if(isInt($var) {
echo 'intero';
} else {
echo 'non intero';
}

Rispondi quotando