Skip to content

Instantly share code, notes, and snippets.

@Riaan-ZA
Created June 22, 2012 13:42
Show Gist options
  • Save Riaan-ZA/2972799 to your computer and use it in GitHub Desktop.
Save Riaan-ZA/2972799 to your computer and use it in GitHub Desktop.
PHP: Validate and Clean inputs function
function validate_and_clean($value, $type = 'text') {
switch ($type) {
case 'text':
$value = filter_var($value, FILTER_SANITIZE_STRING);
$response = true;
break;
case 'email':
$value = filter_var($value, FILTER_SANITIZE_EMAIL);
if(filter_var($value01,FILTER_VALIDATE_EMAIL)) {
$response = true;
} else {
$response = "invalid email";
}
break;
default:
$value = filter_var($value, FILTER_SANITIZE_STRING);
$response = true;
break;
}
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment