我有一个PHP函数来删除任何可能被恶意使用的可疑字符。
<?php
function strip_tags_content($text, $tags = '', $invert = FALSE) {
preg_match_all('/<(.+?)['s]*'/?['s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);
if(is_array($tags) AND count($tags) > 0) {
if($invert == FALSE) {
return preg_replace('@<(?!(?:'. implode('|', $tags) .')'b)('w+)'b.*?>.*?</'1>@si', '', $text);
}
else {
return preg_replace('@<('. implode('|', $tags) .')'b.*?>.*?</'1>@si', '', $text);
}
}
else if($invert == FALSE) {
return preg_replace('@<('w+)'b.*?>.*?</'1>@si', '', $text);
}
return $text;
}
?>
我在这个函数上面有一个Sign Up表单,我想通过这个函数传递每个表单输入,以剥离所有字符。
我该怎么做呢?
$stripped = array();
foreach($_POST as $index => $value){
$stripped[$index] = strip_tags_content($value);
}