How to implement regular replacement tags in php

藏色散人
Release: 2023-03-04 11:42:01
Original
2816 people have browsed it

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!