Checking if a string contains an integer

后端 未结 14 728
北海茫月
北海茫月 2020-12-02 17:10

Do you know of a function that can check if a string contains an integer?

Here\'s how I\'d expect it to work:

holds_int(\"23\") // should return true         


        
14条回答
  •  爱一瞬间的悲伤
    2020-12-02 17:38

    ctype_digit will do the trick:

    ctype_digit($str)

    1. $str has to be a string
    2. extra spaces are not allowed
    3. no decimal points .

提交回复
热议问题