Skip to content

Instantly share code, notes, and snippets.

@dlueth
Created June 27, 2013 21:32
Show Gist options
  • Save dlueth/5880597 to your computer and use it in GitHub Desktop.
Save dlueth/5880597 to your computer and use it in GitHub Desktop.
PHP modifier to sanitize (remove any hostile characters) from any given string
function sanitize($value) {
$value = preg_replace('/[\x00-\x1f\?*:";|\/°^!§$%&\\()=´`+#\':,<>]/', '', trim($value));
$value = preg_replace('/^(?:PRN|AUX|CLOCK\$|NUL|CON|COM\d|LPT\d)(?:\.*)(.*)/', '\1', $value);
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment