And to skip Wizkidje from complaining, here's the escaping for single/double quotes, backslashes, and tags:
Code:
function sanitize ( $data ) {
if ( ! get_magic_quotes_gpc ( ) )
$data = preg_replace ( Array ( '/[\\\[\]]/', '/\'/', '/"/' ), Array ( '\\', '\\\'', '\"' ), $data );
$data = preg_replace ( Array ( '/[\>]/', '/[\<]/' ), Array ( '>', '<' ), $data );
return $data;
}
With comments and decent spacing, for readability:
Code:
function sanitize ( $data )
{
if ( ! get_magic_quotes_gpc ( ) ) // If sanitizing for databasing isn't done..
$data = preg_replace ( Array ( '/[\\\[\]]/', '/\'/', '/"/' ), Array ( '\\', '\\\'', '\"' ), $data ); // ..do so
$data = preg_replace ( Array ( '/[\>]/', '/[\<]/' ), Array ( '>', '<' ), $data ); // Escape tags to prevent tag-injection
return $data;
}