PHP-Way to sanitize input data

by barkkathulla 2014-03-29 11:21:16



Way to sanitize input data


function filterWay($input) {

//you can omit anything depends on your requirement, in this array...
$search = array(
'@<[/!]*?[^<>]*?>@si', // Strip out HTML tags
'@]*?>.*?@siU', // Strip style tags properly
'@]*?>.*?@si', // Strip out javascript
'@
]*>@' // Strip multi-line comments
);

$output = preg_replace($search, '', $input);
return $output;
}
function data_sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = data_sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
$input = filterWay($input);
$output = mysql_real_escape_string($input);
}
return $output;
}
$sample_text= "ENTER YOUR TEXT HERE";
echo $original_output = data_sanitize($sample_text);
?>

841
like
0
dislike
0
mail
flag

You must LOGIN to add comments