check if string is a number

Discussion in 'PHP' started by roice, Nov 10, 2011.

  1. #1
    Hello,
    I have string.
    Is there any function that check if this string is only a numbers?

    Thanks,
    Roi.
     
    roice, Nov 10, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    http://www.php.net/manual/en/function.ctype-digit.php

    if(ctype_digit($string)) {
    echo "it's a number";
    }

    There's also is_numeric, however, I chose ctype functions as they can also test for alpha, upper case, lower case. Check out the page on php.net as there are some limitations.
     
    jestep, Nov 10, 2011 IP
  3. roice

    roice Peon

    Messages:
    200
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks....
     
    roice, Nov 10, 2011 IP