Check if variable is a number and positive integer in PHP?

后端 未结 6 1399
甜味超标
甜味超标 2021-01-24 06:11

For example, say:


How do I check if variable

6条回答
  •  别那么骄傲
    2021-01-24 06:55

    is_int is only for type detection. And request parameters are string by default. So it won't work. http://php.net/is_int

    A type independent working solution:

    if(preg_match('/^\d+$/D',$post_id) && ($post_id>0)){
       print "Positive integer!";
    }
    

提交回复
热议问题