/**
* 过滤html代码中可能存在的js
* */
public static function no_xss($html_string) {
//第一步过滤script标签
$reg1 = "/<\/*script[^>]*>/i"; //忽略大小写
while(preg_match($reg1,$html_string)) {
$html_string = preg_replace($reg1,'',$html_string);
}
//第二步过滤 expression
$reg2 = "/expression/i";
while(preg_match($reg2,$html_string)) {
$html_string = preg_replace($reg2,'',$html_string);
}
//第三步 过滤属性 onerror onload
$reg3 = "/ (on[a-zA-Z]+)/i";
while(preg_match($reg3,$html_string)) {
$html_string = preg_replace($reg3,' ',$html_string);
}
//第四步 过滤协议类型 src=jav scr="" href="" href=
$reg4 = "/(href|src) *\= *('|\"){0,1}([^>^ ^\"^']+)('|\"){0,1}/i";
preg_match_all($reg4,$html_string,$result);
$url_list = $result[3];
foreach($url_list as $v) {
if(!preg_match("/^http\:\/\//i",$v)) {
$html_string = str_replace($v,'',$html_string);
}
}
//第五步 过滤 link标签
$reg5 = "/<\/*link[^>]*>/i"; //忽略大小写
while(preg_match($reg5,$html_string)) {
$html_string = preg_replace($reg5,'',$html_string);
}
//第六步 过滤iframe 标签
$reg6 = "/<\/*iframe[^>]*>/i"; //忽略大小写
while(preg_match($reg6,$html_string)) {
$html_string = preg_replace($reg6,'',$html_string);
}
return $html_string;
}
* 过滤html代码中可能存在的js
* */
public static function no_xss($html_string) {
//第一步过滤script标签
$reg1 = "/<\/*script[^>]*>/i"; //忽略大小写
while(preg_match($reg1,$html_string)) {
$html_string = preg_replace($reg1,'',$html_string);
}
//第二步过滤 expression
$reg2 = "/expression/i";
while(preg_match($reg2,$html_string)) {
$html_string = preg_replace($reg2,'',$html_string);
}
//第三步 过滤属性 onerror onload
$reg3 = "/ (on[a-zA-Z]+)/i";
while(preg_match($reg3,$html_string)) {
$html_string = preg_replace($reg3,' ',$html_string);
}
//第四步 过滤协议类型 src=jav scr="" href="" href=
$reg4 = "/(href|src) *\= *('|\"){0,1}([^>^ ^\"^']+)('|\"){0,1}/i";
preg_match_all($reg4,$html_string,$result);
$url_list = $result[3];
foreach($url_list as $v) {
if(!preg_match("/^http\:\/\//i",$v)) {
$html_string = str_replace($v,'',$html_string);
}
}
//第五步 过滤 link标签
$reg5 = "/<\/*link[^>]*>/i"; //忽略大小写
while(preg_match($reg5,$html_string)) {
$html_string = preg_replace($reg5,'',$html_string);
}
//第六步 过滤iframe 标签
$reg6 = "/<\/*iframe[^>]*>/i"; //忽略大小写
while(preg_match($reg6,$html_string)) {
$html_string = preg_replace($reg6,'',$html_string);
}
return $html_string;
}