PHP regular expression - filter number only

后端 未结 6 667
南旧
南旧 2020-11-30 04:46

I know this might sound as really dummy question, but I\'m trying to ensure that the provided string is of a number / decimal format to use it later on with PHP\'s number_fo

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 05:08

    You could do something like this if you want only whole numbers.

    function make_whole($v){
        $v = floor($v);
        if(is_numeric($v)){
          echo (int)$v;
          // if you want only positive whole numbers
          //echo (int)$v = abs($v);
        }
    }
    

提交回复
热议问题