echo preg_match("^\d+$", $string);

解决方案 »

  1.   

    不好意思,漏了定界符了-_-!
    echo preg_match("/^\d+$/", $string);
      

  2.   

    function check_dog($str)
    {
        if(!isset($str))
          return false;
        if(preg_match('/^\d+$/',$str))
          return true;
        else
          return false;
    }$str = '16888';
    if(check_dog($str))
      print('纯数字字符串');
      

  3.   

    function isNumber($string){
       $length=$strlen($string);
       $flag=1;
       for($i=0;$i<$length;$i++)
          if($string[$i]>'9'||$string[$i]<'0'){
             $flag=0;
             break;
          }
       return $flag;
    }
      

  4.   

    //首先你自己判断空值if( ereg("[^0-9\.]",$str) ) echo "有除数字以外的字符";else echo "为纯数字";//