try this: if (ereg("^[0-9]+$", $_POST["var_int")) echo "is int";
[]īs Felipe ----- Original Message ----- From: "Jean-Christian IMbeault" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, June 11, 2003 9:44 PM Subject: [PHP] How to find if a string is an integer? > I would like to test wether a $_POST var is an integer or not. What is > the best way? > > I ahve tried is_int() but that fails b/c $_POST vars are always strings. > is_numeric() doesn't help because it doesn't differentiate bewteen > numbers (1.0) and integers (1). > > The best I have been able to come up with is: > > if (is_numeric($var) && is_int((int)$var)) > > But I ma hoping there is something simpler ... > > Any ideas? > > thansk, > > Jean-Christian Imbeault > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php