Checking if a string contains an integer

后端 未结 14 749
北海茫月
北海茫月 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 17:29

    Maybe this will also help in given situation there is a function in php that already does this, its called "is_numeric()" it will return true or false accordenly..

       if(is_numeric($somestring) == True){
            echo "this string contains a integar";
        }
    

    link: http://www.php.net/is_numeric

    you said "holdsint("2") should return true, well is_numeric("2") returns True, and is_numeric("a") False, as expected, this function exists in php, no need to rewrite.

提交回复
热议问题