Re: FILTER_VALIDATE_INT - newbie question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Are you using the == operator or === ?
maybe that's the problem

the function could return false or 0. You need to use the === operator

if( false !== ( $value = filter_var($value, FILTER_VALIDATE_INT)))
{
echo 'I need an Integer';
exit;
}
echo 'Thanks for the Int';

On Wed, Oct 7, 2009 at 2:13 PM, Ben Dunlap <bdunlap@xxxxxxxxxxxxxxxxxx>wrote:

> > Also, I think you're getting confused over the zero with exactly what
> > you are asking PHP to do. filter_var() returns true if the filter
> > matches. If the 0 match is returned as a false, then filter_var() will
>
> filter_var() actually returns the filtered data if the filter matches,
> and FALSE if it doesn't. That's the whole point of the filter_XXX
> functions; to pass a tainted value through a filter and get a clean,
> "safe" value out the other end:
>
>    $tainted = get_user_input();
>    $clean = filter_var($tainted, [FILTER_CONSTANT]);
>    // now use $clean and never touch $tainted again
>
> From the original code above, it looks like the OP was
> misunderstanding the use of filter_var() and expecting it to return a
> boolean.
>
> Ben
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Martin Scotta

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux