sanitizeFilename function

Been using this for a while and I can’t remember exactly where it came from.

EDIT: It’s a simplified version of sanitize_file_name used by WordPress.

function sanitizeFilename( $filename )
{
	$special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", chr(0));

	$filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
	$filename = str_replace($special_chars, '', $filename);
	$filename = str_replace( array( '%20', '+' ), '-', $filename );
	$filename = preg_replace('/[\s-]+/', '-', $filename);
	$filename = trim($filename, '.-_');
	
	return $filename;
}