Re: FILTER_VALIDATE_INT - newbie question
| From: | Ben Dunlap | Date: | Wed, 07 Oct 2009 17:13:03 +0000 |
| Subject: | Re: FILTER_VALIDATE_INT - newbie question | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298752@lists.php.net to get a copy of this message | ||
> 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