国产探花免费观看_亚洲丰满少妇自慰呻吟_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. ?>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新昌县| 建平县| 曲阜市| 论坛| 电白县| 广饶县| 尤溪县| 新和县| 乐平市| 建瓯市| 福建省| 泸水县| 滦南县| 茶陵县| 怀化市| 永丰县| 新乐市| 客服| 博兴县| 玉门市| 玉溪市| 泗水县| 册亨县| 屏东市| 拜泉县| 渭南市| 铁岭市| 荥阳市| 南充市| 息烽县| 翁牛特旗| 中牟县| 奇台县| 新营市| 吴堡县| 桐庐县| 隆安县| 达尔| 万山特区| 玉山县| 贵定县|