php过滤提交信息防注入

function filterStr($str) {
	$str = trim($str);
	if (function_exists('strip_tags')) {
		$result = strip_tags($str);
	} else {
		$farr = '/(<\/?)([a-z\d\:]+)((\s+.+?)?>)/isU';
		$tarr = '';
		$result = preg_replace($farr, $tarr, $str);
	}
	$result = strReplace($result, 'all');
	return $result;
}

strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签。boolean function_exists (string function_name),本函数用来检查指定的函数是否已经定义。


主要解决表单提交中存在的一些非法字符

原文地址:https://www.cnblogs.com/y0umer/p/2809630.html