Re: Re: test if $int is integer
| From: | Mark Leavy | Date: | Tue, 29 Jun 2004 22:16:03 +0000 |
| Subject: | Re: Re: test if $int is integer | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-189241@lists.php.net to get a copy of this message | ||
Yeah, 4 will pass the is_int() test, '4' won't.
I prefere just to use if(ctype_digit($foo)){ ... }
On Tue, 29 Jun 2004 15:12:22 -0700 (PDT), Matthew Sims
<matt@killermookie.org> wrote:
> I recently purchased George Schlossnagle's Advanced PHP Programming and on
> page 85 in the Error Handling chapter, he made a reference about the
> is_int function.
>
> In the above function example he had:
> if (!preg_match('/^\d+$/',$n) || $n < 0) {....
>
> In which he mentions:
> It might be strange to choose to evaluate whether $n is an integer by
> using a regular expression instead of the is_int function. The is_int
> function, however, does not do what you want. It only evaluates whether $n
> has been typed as a string or as an integer, not whether the value of $n
> is an integer.
>
> Can anyone comment on this?
>
> --Matthew Sims
> --<http://killermookie.org>