Search code examples
phpvalidationsanitization

Warning: filter_var() expects parameter 2 to be long, string given in


In this code I get a warning

Warning: filter_var() expects parameter 2 to be long, string given in the last line

$check = filter_var($email, FILTER_SANITIZE_EMAIL);
$str = filter_var($name, FILTER_SANITIZE_STRING);
if (!filter_var($check, FILTER_VALIDATE_EMAIL) && !filter_var($str, FILTER_VALIDATE_STRING)) { //here

The problem is this, because without it no exists any warning message

 !filter_var($str, FILTER_VALIDATE_STRING)

What is the reason of this error?


Solution

  • There is no such filter as FILTER_VALIDATE_STRING... could you just use is_string?