/** |
* 过滤字符串并转义 |
* 当 $editor 为 true 时,则不会转换 '<' 和 '>' |
* |
* @param $data data |
* @param $editor 是否使用了编辑器 |
* |
*/ |
function strip( $data , $editor = false){ |
$data = strtr ( $data , '`' , '' ); |
if ( $editor == true){ |
// 过滤 html标签黑名单 |
$search = array ( |
'#<script[^>]*?>.*?[</script>]*#si' , |
'#<iframe[^>]*?>.*?[</iframe>]*#si' , |
'#<input[^>]*?>#si' , |
'#<button[^>]*?>.*?</button>#si' , |
'#<form[^>]*?>#si' , |
'#</form>#si' , |
'#(<[\/\!]*?)?(\ class\=[\'|"].*?[\'|"])|(\ id\=[\'|"].*?[\'|"])([^<>]*?>)?#si' |
); |
$replace = array ( |
'' , |
'' , |
'' , |
'' , |
'' , |
'' |
); |
$data = preg_replace( $search , $replace , $data ); |
if (get_magic_quotes_gpc()){ |
$data = trim( $data ); |
} else { |
$data = addslashes (trim( $data )); |
} |
} else { |
if (get_magic_quotes_gpc()){ |
$data = htmlspecialchars(trim( stripslashes ( $data )),ENT_QUOTES); |
} else { |
$data = htmlspecialchars(trim( $data ),ENT_QUOTES); |
} |
} |
return $data ; |
} |