Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Last active February 11, 2016 06:37
Show Gist options
  • Select an option

  • Save hsleonis/099742dfd37ca4bcde2b to your computer and use it in GitHub Desktop.

Select an option

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
<?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