dlueth
6/27/2013 - 9:32 PM

PHP modifier to sanitize (remove any hostile characters) from any given string

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;
}