Home > Article > Backend Development > How to implement regular replacement tags in php
##Recommended: "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 /","")".
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 replacementstr_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 tagsstr=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!