Re: Converting variables to integer
| From: | Kevin Stone | Date: | Wed, 06 Nov 2002 18:52:46 +0000 |
| Subject: | Re: Converting variables to integer | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-123044@lists.php.net to get a copy of this message | ||
Ooops my str_replace() function needs one more parameter.
str_replace(',', '', $str);
-Kevin
----- Original Message -----
From: "Kevin Stone" <kevin@helpelf.com>
To: <php-general@lists.php.net>; <drparker@clam.rutgers.edu>
Sent: Wednesday, November 06, 2002 11:45 AM
Subject: Re: [PHP] Converting variables to integer
>
> function str2int($str)
> {
> $str = str_replace(',', $str); //
> http://www.php.net/manual/en/function.str-replace.php
>
> settype($str, "integer"); //
> http://www.php.net/manual/en/function.settype.php
>
> if (is_int($str)) //
> http://www.php.net/manual/en/function.is-int.php
> return $str;
> else
> return false;
> }
>
> Loop through your form variables and call this function. Good luck,
> -Kevin
>
>
> ----- Original Message -----
> From: <drparker@clam.rutgers.edu>
> To: <php-general@lists.php.net>
> Sent: Wednesday, November 06, 2002 9:05 AM
> Subject: [PHP] Converting variables to integer
>
>
> > I have a bunch of form variables that I need to process as integers.
> > The problem is that some users are writing in values with commas - e.g.
> > 100,000, and that isn't read as an integer. There's more than one
> > variable so I don't want to have to do a string replace for each one.
> > Is there a general way to curb this problem?
> >
> > Thanks, Doug
> >
> >
> > --
> > 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
>
>