Return to Snippet

Revision: 39535
at January 18, 2011 04:37 by kendsnyder


Initial Code
// based on Quad_Scrub: http://code.google.com/p/quadphp/source/browse/trunk/library/Quad/Scrub.php
function clean(&$val, $allowedChars = 'ascii') {
	static $types = array(
		'word'         => '/[^a-zA-Z\x{00C0}-\x{00FF}\x{0100}-\x{02AF}\x{1E00}-\x{1EF9}\d -\/:;=\?@\[-_\{-~
\t\.]/u',
		'alpha'        => '/[^a-zA-Z\x{00C0}-\x{00FF}\x{0100}-\x{02AF}\x{1E00}-\x{1EF9}]/u',
		'alphanum'     => '/[^a-zA-Z\x{00C0}-\x{00FF}\x{0100}-\x{02AF}\x{1E00}-\x{1EF9}\d]/u',
		'id'           => '/[^\w_]/',
		'date'         => '/[^\d :TzZ-]/',
		'email'        => "/[^@\w\.!#$%&'*+\-\/=?^_`{|}~]/", // http://en.wikipedia.org/wiki/E-mail_address Dec 2009
		'url'          => '/[^\w\._&?#+%=\/~:-]/',
		'ascii'        => '/[^ -~]/',
	);
	if (isset($types[$allowedChars])) {
		$regex = $types[$allowedChars];
	}
	else {
		$regex = $allowedChars;
	}
	$val = preg_replace($regex, '', (string) $val);
	return $val;
}

Initial URL


Initial Description


Initial Title
Clean incoming POST data

Initial Tags
post, security

Initial Language
PHP