php validate integer

前端 未结 7 1302
南旧
南旧 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:32

    It sounds like you are checking if a string contains an integer, rather than if that variable is an integer. If so, you should check out php's regex (regular expression) functionality. It allows you to check for very specific patterns in a string to validate it for whatever criteria. (such as if it contains only number characters)

    Here's the php page http://php.net/manual/en/function.preg-match.php

    and here's a cheat sheet on regular expressions (to make the $pattern string) http://regexpr.com/cheatsheet/

    0 讨论(0)
提交回复
热议问题