php validate integer

前端 未结 7 1342
南旧
南旧 2020-11-28 10:43

I`m wonder why this not working

    echo gettype($_GET[\'id\']); //returns string
  if(is_int($_GET[\'id\']))
  {
   echo \'Integer\';
  }

7条回答
  •  误落风尘
    2020-11-28 11:06

    To validate form data (string) as an integer, you should use ctype_digit() It returns TRUE if every character in the string text is a decimal digit, FALSE otherwise. (PHP 4 >= 4.0.4, PHP 5)

    Reference: http://php.net/manual/en/function.ctype-digit.php

提交回复
热议问题