is_int and GET or POST

后端 未结 10 1272
傲寒
傲寒 2020-12-14 10:44

Why does is_int always return false in the following situation?

echo $_GET[\'id\']; //3
if(is_int($_GET[\'id\']))
    echo \'int\'; //not execut         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 11:06

    Prabably best way to check if value from GET or POST is integer is check by preg_match

    if( preg_match('/^[0-9]+$/', $_GET['id'] ){
       echo "is int";
    }
    

提交回复
热议问题