Function to count number of digits in string

前端 未结 4 2225
梦毁少年i
梦毁少年i 2020-12-15 04:15

I was looking for a quick PHP function that, given a string, would count the number of numerical characters (i.e. digits) in that string. I couldn\'t find one, is there a fu

4条回答
  •  被撕碎了的回忆
    2020-12-15 05:09

    This function goes through the given string and checks each character to see if it is numeric. If it is, it increments the number of digits, then returns it at the end.

    function countDigits($str) {
        $noDigits=0;
        for ($i=0;$i

提交回复
热议问题