部分強大的線上編輯器,已經包含了程式碼整理,過濾功能,但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);//刪除。 。 。 格式,//$str=preg_replace("/<(script.*?)>(.*?)<(//script.*?)>/si", "/1>//2/3>",$str);//替換為可顯示的,$str=preg_replace("/<(script.*?) >/si","",$str);//刪除未封閉<br>//$str=preg_replace("/<(script.*?)>/si","< ;//1>",$str);//替換未封閉<br><br>/*刪除/替換表單*/<br>$str=preg_replace("/<(//?form.*? )>/si","",$str);//刪除表單<br>//$str=preg_replace("/<(//?form.*?)>/si","< //1>",$str);//替換表單<br><br>$str=preg_replace("/<(i?frame.*?)>(.*?)<(//i ?frame.*?)>/si","",$str);//刪除框架<br>//$str=preg_replace("/<(i?frame.*?)>(.* ?)<(//i?frame.*?)>/si","<//1>//2<//3>",$str);//替換框架<br><br>/*過濾on事件*/<br>$str=preg_replace("/href=(.+?)([/"|/'| |>])/ie","'href='.strtoupper( '//1').'//2'",$str);//把href=涉及的on轉換為大寫。<br>$str=str_replace($htm_on,$htm_on_uper,$str);/ /把<font,font>換成大寫,dhtml標籤字符,正規判斷太煩瑣,採用轉換辦法。 [ |>])/s","//2",$str);//取掉on事件<br><br>/*過濾超級連接的js*/<br>$str=preg_replace(" /(href|src|background|url|dynsrc|expression|codebase)[=:/(]([ /"/']*?/w+/..*?|javascript|vbscript:[^>]*? )(/)?)([ >//])/si","//1='#' //3//4",$str);//取掉href=javascript:<br><br>//回傳小寫字元<br>$str=strtolower($str);<br>$str=str_replace("&","&",$str);<br></p> <div></div> <!--<p class='doc-content-pic doc-pic'> <img src="https://img.php.cn/upload/article/000/000/007/ff385415f5502cad4a11468c06fab82e-0.jpg" / alt="過濾html線上編輯器產生有危害代碼" >-->