First letter is number in string

后端 未结 5 2038
忘掉有多难
忘掉有多难 2020-12-11 01:55

I was trying to find a quick and easy method to check if the first letter in a string is a number. A lot of the functions and methods I\'ve seen on S.O seem over complicated

5条回答
  •  無奈伤痛
    2020-12-11 02:38

    No, that would not work. You might get "Notice: Uninitialized string offset: 0" notice. To make it work, add strlen():

    if ( strlen($string) > 0 && is_numeric($string[0]) ) {
    }
    

提交回复
热议问题