Last active
February 11, 2016 06:37
-
-
Save hsleonis/099742dfd37ca4bcde2b to your computer and use it in GitHub Desktop.
This PHP filters is used to validate and filter data coming from insecure sources, like user input. PHP 5.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Reference: http://www.w3schools.com/php/php_ref_filter.asp | |
| $bool = filter_var($bool, FILTER_VALIDATE_BOOLEAN); | |
| $email = filter_var($email, FILTER_SANITIZE_EMAIL); | |
| $newstr = filter_var($str, FILTER_SANITIZE_STRING); | |
| $url = filter_var($var, FILTER_SANITIZE_URL); | |
| // Example: Mail validation | |
| $email = "john.doe@example.com"; | |
| // Remove all illegal characters from email | |
| $email = filter_var($email, FILTER_SANITIZE_EMAIL); | |
| // Validate e-mail | |
| if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) { | |
| echo("$email is a valid email address"); | |
| } else { | |
| echo("$email is not a valid email address"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment