Home > Backend Development > PHP Tutorial > Code example of php regular filtering html tags, spaces, newlines, etc.

Code example of php regular filtering html tags, spaces, newlines, etc.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 09:04:40
Original
1059 people have browsed it
  1. /**

  2. desc: regular filtering of html tags, spaces, newlines, etc.
  3. link: bbs.it-home.org
  4. date: 2013/2/23
  5. */
  6. $str=preg_replace("/s+/", " ", $str); //Filter excess carriage returns
  7. $ str=preg_replace("/<[ ]+/si","<",$str); //Filter<__("<" followed by a space)

  8. $str=preg_replace("//si","",$str); //Comment

  9. $str=preg_replace("/<(!.*?)> ;/si","",$str); //Filter DOCTYPE
  10. $str=preg_replace("/<(/?html.*?)>/si","",$str); //Filter html tag
  11. $str=preg_replace("/<(/?head.*?)>/si","",$str); //Filter head tag
  12. $str=preg_replace("/<(/ ?meta.*?)>/si","",$str); //Filter meta tags
  13. $str=preg_replace("/<(/?body.*?)>/si","" ,$str); //Filter the body tag
  14. $str=preg_replace("/<(/?link.*?)>/si","",$str); //Filter the link tag
  15. $str= preg_replace("/<(/?form.*?)>/si","",$str); //Filter form tag
  16. $str=preg_replace("/cookie/si","COOKIE",$ str); //Filter COOKIE tag

  17. $str=preg_replace("/<(applet.*?)>(.*?)<(/applet.*?)> ;/si","",$str); //Filter applet tags

  18. $str=preg_replace("/<(/?applet.*?)>/si","",$str); // Filter applet tags

  19. $str=preg_replace("/<(style.*?)>(.*?)<(/style.*?)>/si", "",$str); //Filter style tags

  20. $str=preg_replace("/<(/?style.*?)>/si","",$str); //Filter style tags< /p>
  21. $str=preg_replace("/<(title.*?)>(.*?)<(/title.*?)>/si","",$str ); //Filter the title tag

  22. $str=preg_replace("/<(/?title.*?)>/si","",$str); //Filter the title tag

  23. < ;p>$str=preg_replace("/<(object.*?)>(.*?)<(/object.*?)>/si","",$str); //Filter object tag
  24. $str=preg_replace("/<(/?objec.*?)>/si","",$str); //Filter object tag

  25. $str =preg_replace("/<(noframes.*?)>(.*?)<(/noframes.*?)>/si","",$str); //Filter noframes tag

  26. $str =preg_replace("/<(/?noframes.*?)>/si","",$str); //Filter noframes tag

  27. $str=preg_replace("/ <(i?frame.*?)>(.*?)<(/i?frame.*?)>/si","",$str); //Filter frame tag

  28. $str= preg_replace("/<(/?i?frame.*?)>/si","",$str); //Filter frame tag

  29. $str=preg_replace(" /<(script.*?)>(.*?)<(/script.*?)>/si","",$str); //Filter script tags

  30. $str=preg_replace(" /<(/?script.*?)>/si","",$str); //Filter script tags
  31. $str=preg_replace("/javascript/si","Javascript",$str); //Filter script tags
  32. $str=preg_replace("/vbscript/si","Vbscript",$str); //Filter script tags
  33. $str=preg_replace("/on([a-z]+)s*=/ si","On\1=",$str); //Filter script tags
  34. $str=preg_replace("//si","",$str); //Filter script tags, such as javAsCript :alert(
  35. ?>

Copy code


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template