Re: problem with intval and !=
| From: | Robert Cummings | Date: | Thu, 23 Oct 2003 16:51:29 +0000 |
| Subject: | Re: problem with intval and != | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-167317@lists.php.net to get a copy of this message | ||
On Thu, 2003-10-23 at 12:41, John W. Holmes wrote:
> Greg Beaver wrote:
>
> > http://www.php.net/is_numeric
> >
> > is the function you are looking for. No need for fancy regexps.
>
> The OP is looking for an integer, but is_numeric() will return true for
> float values and also for numbers in scientific notation. So "12.3" and
> "12E3" will be TRUE.
>
> The original $number != intval($number) should work for detecting bad
> input.
This doesn't work John, because the the != will convert the $number to
an intval for the comparison; however, after reflecting on your code and
the style you used.. hte following will work :)
$foo = '123fooo';
if( trim( $foo ) != ''.intval( $foo ) )
{
echo "Not same beast!\n";
}
else
{
echo "Same beast!\n";
}
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'