国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php正則表達式匹配html過濾非法字符

2024-09-04 11:47:36
字體:
來源:轉載
供稿:網友

匹配一個html標簽,匹配table如下:<table.*?>[ss]*</table> 或 :<table.*?>[ss]*?</table>,以上兩個表達式,一個加了"?"和一個卻不加"?",那么這有什么區別呢?

我們知道"?"在正則表達式里是一個通配符:匹配前面的子表達式零次或一次,或指明一個非貪婪限定符.

在這里,通過測試,我們得出這樣的結論:在不加"?"的情況下,在匹配下面一段內容的時候:

<table>這是第一個table</table> 我不是table里的內容 

<table>這是第二個table</table> 我也不是table里的內容

<table>這是第三個table</table>

  1. <?php 
  2. $str=preg_replace("/s+/"" "$str); //過濾多余回車 
  3. $str=preg_replace("/<[ ]+/si","<",$str); //過濾<__("<"號后面帶空格) 
  4. $str=preg_replace("/<!--.*?-->/si","",$str); //注釋 
  5. $str=preg_replace("/<(!.*?)>/si","",$str); //過濾doctype 
  6. $str=preg_replace("/<(/?html.*?)>/si","",$str); //過濾html標簽 
  7. $str=preg_replace("/<(/?head.*?)>/si","",$str); //過濾head標簽 
  8. $str=preg_replace("/<(/?meta.*?)>/si","",$str); //過濾meta標簽 
  9. $str=preg_replace("/<(/?body.*?)>/si","",$str); //過濾body標簽 
  10. $str=preg_replace("/<(/?link.*?)>/si","",$str); //過濾link標簽 
  11. $str=preg_replace("/<(/?form.*?)>/si","",$str); //過濾form標簽 
  12. $str=preg_replace("/cookie/si","cookie",$str); //過濾cookie標簽 
  13. $str=preg_replace("/<(applet.*?)>(.*?)<(/applet.*?)>/si","",$str); //過濾applet標簽 
  14. $str=preg_replace("/<(/?applet.*?)>/si","",$str); //過濾applet標簽 
  15. $str=preg_replace("/<(style.*?)>(.*?)<(/style.*?)>/si","",$str); //過濾style標簽 
  16. $str=preg_replace("/<(/?style.*?)>/si","",$str); //過濾style標簽 
  17. $str=preg_replace("/<(title.*?)>(.*?)<(/title.*?)>/si","",$str); //過濾title標簽 
  18. $str=preg_replace("/<(/?title.*?)>/si","",$str); //過濾title標簽 
  19. $str=preg_replace("/<(object.*?)>(.*?)<(/object.*?)>/si","",$str); //過濾object標簽 
  20. $str=preg_replace("/<(/?objec.*?)>/si","",$str); //過濾object標簽 
  21. $str=preg_replace("/<(noframes.*?)>(.*?)<(/noframes.*?)>/si","",$str); //過濾noframes標簽 
  22. $str=preg_replace("/<(/?noframes.*?)>/si","",$str); //過濾noframes標簽 
  23. $str=preg_replace("/<(i?frame.*?)>(.*?)<(/i?frame.*?)>/si","",$str); //過濾frame標簽 
  24. $str=preg_replace("/<(/?i?frame.*?)>/si","",$str); //過濾frame標簽 
  25. $str=preg_replace("/<(script.*?)>(.*?)<(/script.*?)>/si","",$str); //過濾script標簽 
  26. $str=preg_replace("/<(/?script.*?)>/si","",$str); //過濾script標簽 
  27. $str=preg_replace("//si","javascript",$str); //過濾script標簽 
  28. $str=preg_replace("/vbscript/si","vbscript",$str); //過濾script標簽 
  29. $str=preg_replace("/on([a-z]+)s*=/si","on/1=",$str); //過濾script標簽 
  30. $str=preg_replace("/&#/si","&#",$str); //過濾script標簽,如javascript:alert('aabb)//開源軟件:Vevb.com 
  31. ?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 牙克石市| 武宁县| 汕尾市| 左权县| 福安市| 留坝县| 曲麻莱县| 萨嘎县| 河池市| 彰化县| 荣成市| 乌拉特中旗| 改则县| 潢川县| 子洲县| 五家渠市| 岑巩县| 峨边| 宁安市| 新郑市| 四平市| 玉林市| 盐山县| 金阳县| 漳平市| 张北县| 阳山县| 英吉沙县| 固原市| 兴国县| 南充市| 隆安县| 库伦旗| 新昌县| 宜都市| 北宁市| 仁寿县| 沙湾县| 拜泉县| 南江县| 蒲城县|