Home > Backend Development > PHP Tutorial > Code for php regular filtering of html tags, spaces, and line breaks with instructions

Code for php regular filtering of html tags, spaces, and line breaks with instructions

WBOY
Release: 2016-07-29 08:43:55
Original
986 people have browsed it

Copy the code The code is as follows:


$str=preg_replace("/s+/", " ", $str); //Filter excess carriage returns
$str=preg_replace("/<[ ]+ /si","<",$str); //Filter <__("<" with a space after it)
$str=preg_replace("// si","",$str); //Comment
$str=preg_replace("/<(!.*?)>/si","",$str); //Filter DOCTYPE
$str= preg_replace("/<(/?html.*?)>/si","",$str); //Filter html tags
$str=preg_replace("/<(/?head.*?) >/si","",$str); //Filter the head tag
$str=preg_replace("/<(/?meta.*?)>/si","",$str); / /Filter meta tags
$str=preg_replace("/<(/?body.*?)>/si","",$str); //Filter body tags
$str=preg_replace("/< (/?link.*?)>/si","",$str); //Filter link tag
$str=preg_replace("/<(/?form.*?)>/si", "",$str); //Filter form tag
$str=preg_replace("/cookie/si","COOKIE",$str); //Filter COOKIE tag
$str=preg_replace("/<(applet .*?)>(.*?)<(/applet.*?)>/si","",$str); //Filter applet tags
$str=preg_replace("/<(/ ?applet.*?)>/si","",$str); //Filter applet tags
$str=preg_replace("/<(style.*?)>(.*?)<( /style.*?)>/si","",$str); //Filter style tag
$str=preg_replace("/<(/?style.*?)>/si","" ,$str); //Filter style tag
$str=preg_replace("/<(title.*?)>(.*?)<(/title.*?)>/si","" ,$str); //Filter the title tag
$str=preg_replace("/<(/?title.*?)>/si","",$str); //Filter the title tag
$str= preg_replace("/<(object.*?)>(.*?)<(/object.*?)>/si","",$str); //Filter object tag
$str= preg_replace("/<(/?objec.*?)>/si","",$str); //Filter object tag
$str=preg_replace("/<(noframes.*?)> (.*?)<(/noframes.*?)>/si","",$str); //Filter noframes tag
$str=preg_replace("/<(/?noframes.*?) >/si","",$str); //Filter noframes tag
$str=preg_replace("/<(i?frame.*?)>(.*?)<(/i?frame .*?)>/si","",$str); //Filter frame tag
$str=preg_replace("/<(/?i?frame.*?)>/si","" ,$str); //Filter frame tag
$str=preg_replace("/<(script.*?)>(.*?)<(/script.*?)>/si","" ,$str); //Filter script tags
$str=preg_replace("/<(/?script.*?)>/si","",$str); //Filter script tags
$str= preg_replace("/javascript/si","Javascript",$str); //Filter script tags
$str=preg_replace("/vbscript/si","Vbscript",$str); //Filter script tags
$ str=preg_replace("/on([a-z]+)s*=/si","On\1=",$str); //Filter script tags
$str=preg_replace("//si", "",$str); //Filter script tags, such as javAsCript:alert(

The above introduces the code and instructions for PHP regular filtering of HTML tags, spaces, and newlines, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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