|
Function cleanInput ($ input ){
$ Search = array (
'@] *?>. *? @ Si', // Strip out javascript
'@ <[\/\!] *? [^ <>] *?> @ Si', // Strip out HTML tags
'@
] *?>. *?
@ SiU ', // Strip style tags properly
'@' // Strip multi-line comments
);
$ Output = preg_replace ($ search, '', $ input );
Return $ output;
}
Function sanitize ($ input ){
If (is_array ($ input )){
Foreach ($ input as $ var => $ val ){
$ Output [$ var] = sanitize ($ val );
}
}
Else {
If (get_magic_quotes_gpc ()){
$ Input = stripslashes ($ input );
}
$ Input = cleanInput ($ input );
$ Output = mysql_real_escape_string ($ input );
}
Return $ output;
}
// Usage:
$ Bad_string = "Hi! It's a good day! ";
$ Good_string = sanitize ($ bad_string );
// $ Good_string returns "Hi! It \'s a good day! "
// Also use for getting POST/GET variables
$ _ POST = sanitize ($ _ POST );
$ _ GET = sanitize ($ _ GET );
|