Re: int or not int :) ?
| From: | Monte Ohrt | Date: | Fri, 01 Sep 2000 16:32:18 +0000 |
| Subject: | Re: int or not int :) ? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14832@lists.php.net to get a copy of this message | ||
if(!(ereg("[^0-9.]+",$var)))
$var = (int) $var;
else
echo "invalid: $var\n";
James Moore wrote:
>
> >
> > 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/