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

首頁 > 語言 > PHP > 正文

php利用正則過濾鏈接、標簽,空格,換行符程序

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

strip_tags函數

strip_tags --- 去除字串中的HTML和PHP標簽

語法:string strip_tags (string str [, string allowable_tags])

例,代碼如下:

  1. <?php 
  2. $text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>'
  3. echo strip_tags($text); 
  4. echo "n";
  5. // Allow <p> and <a> 
  6. echo strip_tags($text'<p><a>'); 
  7. ?> 

正則過濾各種標簽,空格,換行符,代碼如下:

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

php 正則過濾html 的超鏈接,代碼如下:

  1. <?php  
  2. echo preg_replace("/(?<=href=)([^>]*)(?=>)/i","#""<a href='www.survivalescaperooms.com'>你好,點這里看看</a><a href='www.survivalescaperooms.com'>你好,點這里看看</a>");  
  3. ?> 

正則:/(?<=href=)([^>]*)(?=>)/ 

(?<=exp) 匹配exp后面的位置 

(?=exp) 匹配exp前面的位置 

此正則 匹配 在 href= 之后 “>” 之前 的 非 “>” 的所有字符 

例子:<a href='www.survivalescaperooms.com'>,找到這些字符(url)用 # 替換,就可以去掉html里的所有鏈接.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博野县| 蒲江县| 桐庐县| 通化县| 松潘县| 云安县| 鹤山市| 莫力| 大荔县| 慈利县| 孝感市| 北宁市| 鲁山县| 常德市| 南雄市| 仙桃市| 龙川县| 巩留县| 湟中县| 北辰区| 阜康市| 沾化县| 崇州市| 中西区| 娄底市| 承德县| 嘉荫县| 中江县| 思茅市| 喀喇| 丹寨县| 环江| 葵青区| 遵义市| 临澧县| 满洲里市| 玉树县| 图们市| 富源县| 渭南市| 高碑店市|