RE: [PHP] int or not int :) ?
| From: | James Moore | Date: | Fri, 01 Sep 2000 11:25:36 +0000 |
| Subject: | RE: [PHP] int or not int :) ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14794@lists.php.net to get a copy of this message | ||
>
> How can I determine if a variable is an integer? I tried
> is_int($var) but it
> didn't work.
> I take these variables from a form and insert them in a table.
>
OK if you know the var will always have int values then you can do an easy
$var = (int) $var;
but if var contains a sting PHP can screw you about when casting so mybe
somthing like this:
/* You need to test this or one of the regex gurus need to tell me if this
is right... */
if(!ereg("^[a-zA-Z]+",$var)) {
$var = (int)$var;
}
else {
//$var is not an int!!
}
HTH
James