Home  >  Article  >  Backend Development  >  How to implement regular replacement tags in php

How to implement regular replacement tags in php

藏色散人
藏色散人Original
2020-08-13 09:24:092849browse

How to implement regular replacement tags in php: first strip the HTML tags in the string through the "strip_tags" function; then use regular expressions to replace the tags, code statements such as "pregreplace("/\s /", "",str=pregreplace("/\s /","")".

How to implement regular replacement tags in php

##Recommended: "

PHP Video Tutorial"

1.strip_tags (Strip the HTML tags in the string)

strip_tags () function strips HTML, XML and PHP tags in strings.

2. String replacement

str_replace(array(" "," ","\t" ,"\r\n","\r","\n"),array("","","","","","")

3. Use regular expressions Formula (slightly less efficient)

str=pregreplace("/\s /","",str); //Filter excess carriage returns

str=pregreplace("/<[] /si","<",str); //Filter <__(with a space after the "<" sign)

str=pregreplace("/<−−.∗?−−>/si","",str); //Comments

##str=pregreplace("/< ;(.∗?)>/si","",str); //Filter DOCTYPE

##str=pregreplace("/<(\/?html.∗? )>/si","",str); //Filter html tags

##str=pregreplace("/<(\/?body.∗?)>/si","",str) ; //Filter body tag

str=pregreplace("/<(\/?link.∗?)>/si","",str); //Filter link tag

str=pregreplace("/<(\/?form.∗?)>/si","",str); //Filter form tag

str=pregreplace("/cookie/si","COOKIE",str); //Filter COOKIE tags

str=pregreplace(" /<(applet.?)>(.*?)<(\/applet.*?)>/si","",str); //Filter applet tags

str=pregreplace("/<(\/?applet.∗?)>/si","",str); //Filter applet tags

str=pregreplace("/<(style.∗?)>(.∗?)<(\/style.∗?)>/si","",str); //Filter style tag

str=pregreplace("/<(\/?style.∗?)>/si","",str); //Filter style tags

str=pregreplace("/<(title.∗?)>(.∗?)<(\/title.∗?)>/si","",str); //Filter title tag

str=pregreplace("/<(\/?title.∗?)>/si","",str); //Filter title Tag

##str=pregreplace("/<(object.∗?)>(.∗?)<(\/object.∗?)>/si", "",str); //Filter object tag

##str=pregreplace("/<(\/?objec.∗?)>/si","",str ; >/si","",str); //Filter noframes tag

##str=pregreplace("/<(i?frame.∗?)>(.∗?)< (\/i?frame.∗?)>/si","",str); //Filter frame tag

##str=pregreplace("/<(\/ ?i?frame.∗?)>/si","",str); //Filter frame tag

##str=pregreplace("/<(script.∗? )>(.∗?)<(\/script.∗?)>/si","",str); //Filter script tags

##str=pregreplace("/vbscript/si","Vbscript ",str); //Filter script tags

##str=pregreplace("/on([a−z] )\s∗=/si","On1=",str ); //Filter script tags

str=preg_replace("//si","",str); //Filter script tags, such as javAsCript:alert(

##str=pregreplace("/<(\/?.∗?)>/si","",str);//Match any html tag method

this−>content=pregreplace("/<(\/?.∗?)>/si","",this->content);// Filter most html tags

The above is the detailed content of How to implement regular replacement tags in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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