PHP filter_var function outputs nothing

I have the following code:

$email = '[email protected]';
echo $email.'<br>';
echo filter_var('[email protected]',FILTER_SANITZE_EMAIL).' SANITIZED-EMAIL';

and it the output is as follows:

[email protected]

Clearly the email is completely turned into an empty string. Similarly the filter_var with FILTER_SANITIZE_STRING does the same thing. What am I missing here?


1 Answers PHP filter_var function outputs nothing

Your code does give errors:

Notice: Use of undefined constant FILTER_SANITZE_EMAIL - assumed 'FILTER_SANITZE_EMAIL' in /var/www/html/test.php on line 4

Warning: filter_var() expects parameter 2 to be long, string given in /var/www/html/test.php on line 4 SANITIZED-EMAIL

It has to be FILTER_SANITIZE_EMAIL not FILTER_SANITZE_EMAIL - so it's just a typo.

4 months ago