25 julio, 2024

    When you extract the number value directly from $_POST, its data type is a string.
    You could use is_numeric to check:

    Code:

    if (is_numeric($theNum)) {
        echo $theNum . ” is a number”;
    } else {
        echo $theNum . ” is not a number”;
    }

    or a regular expression

    Code:

    if (preg_match(‘/^d+$/’, $theNum)) {
        echo $theNum . ” is a number”;
    } else {
        echo $theNum . ” is not a number”;
    }

    If you want to cast to an integer data type:

    Code:

    $theNum = (int)$_POST[‘thenum’];
    echo is_int($theNum) ? ‘Number’ : ‘Not’; //Number

    http://www.webdeveloper.com/forum/showthread.php?255676-is_int%28%29-not-working-returning-false

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *