",""," ","","

首頁  >  文章  >  web前端  >  過濾html線上編輯器產生有危害代碼

過濾html線上編輯器產生有危害代碼

巴扎黑
巴扎黑原創
2017-03-30 15:01:211904瀏覽

部分強大的線上編輯器,已經包含了程式碼整理,過濾功能,但js處理的能被很輕易的饒過,服務端必須要再次過濾一次,這幾天花了點時間,寫了部分,希望對大家有點用處,本人能力有限,還請有能力的朋友補全它。



/*不需要過濾的陣列*/
$htm_on=array(
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"font");

$htm_on_uper=array(
"",
"",
"< BUTTON","BUTTON>",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"FONT");

#/*字元格式*/
$str=strtolower($str);
$str=preg_replace("//s+/", " ", $str);//過濾回車
$str=preg_replace ("/ +/", " ", $str);//過濾多個空格

/*過濾/取代幾種形式的js*/
$str=preg_replace("/< (script.*?)>(.*?)<(//script.*?)>/si","",$str);//刪除<script>。 。 。 </script>格式,
//$str=preg_replace("/<(script.*?)>(.*?)<(//script.*?)>/si", "//2",$str);//替換為可顯示的,

$str=preg_replace("/<(script.*?) >/si","",$str);//刪除