View Full Version : Resolved Filter_var issue

04-11-2012, 08:23 PM
I'm writing a sanitizer, which runs filter_var and I'm passing the filter in a function call like

$Filter = array('Email' => 'FILTER_SANITIZE_EMAIL');
$Sanitizer = new Sanitizer();
foreach($_POST as $PostKey => $PostValue){
$Sanitized = $Sanitizer->Sanitize($PostValue, $Filter[$PostKey]);
When I run the code I get this error:

Warning: filter_var() expects parameter 2 to be long, string given.
I'm just passing the filter value as it is. As the error says it expects a long I've tried typecasting the filter as a int, but that just changes it to a 0, on the PHP Manual there are no numbers which correspond to each filter. Any ideas of how to fix this?
Thanks for any help.

04-11-2012, 08:26 PM
We can't see the actual filter_var call, but if it does what I think you are doing then the problem is the 'FILTER_SANITIZE_EMAIL'. This is a constant representing a bitwise value. That should simply be FILTER_SANITIZE_EMAIL without the quotes.

Oh yeah one other possible solution. If for whatever reason these have to be strings (such as stored in a db), then you may invoke it by calling the constant() function to determine the value from the string name.

04-11-2012, 08:40 PM
It issue with it being in quotes fixed it. Thanks for the help.