php正则替换标签的实现方法

php正则替换标签的实现方法:首先通过“strip_tags”函数剥去字符串中的HTML标签;然后利用正则表达式替换标签,代码语句如“pregreplace("/\\\\s /","",str=pregreplace("/\\\\s /","")”。

推荐:《PHP视频教程》

1.strip_tags(剥去字符串中的 HTML 标签)

strip_tags() 函数剥去字符串中的 HTML、XML 以及 PHP 的标签。

2.字符串替换

str_replace(array(“ ”,” ”,”\\\\t”,”\\\\r\\\\n”,”\\\\r”,”\\\\n”),array(“”,”“,”“,”“,”“,”“)

3.利用正则表达式(效率稍微低一些)

str=pregreplace("/\\\\s /","",str); //过滤多余回车

str=pregreplace("/<[] /si","<",str); //过滤<__(“<”号后面带空格)

str=pregreplace("/<??.????>/si","",str); //注释

str=pregreplace("/<(.??)>/si","",str); //过滤DOCTYPE

str=pregreplace("/<(\\\\/?html.??)>/si","",str); //过滤html标签

str=pregreplace("/<(\\\\/?head.??)>/si","",str); //过滤head标签

str=pregreplace("/<(\\\\/?meta.??)>/si","",str); //过滤meta标签

str=pregreplace("/<(\\\\/?body.??)>/si","",str); //过滤body标签

str=pregreplace("/<(\\\\/?link.??)>/si","",str); //过滤link标签

str=pregreplace("/<(\\\\/?form.??)>/si","",str); //过滤form标签

str=pregreplace("/cookie/si","COOKIE",str); //过滤COOKIE标签

str=pregreplace("/<(applet.??)>(.??)<(\\\\/applet.??)>/si","",str); //过滤applet标签

str=pregreplace("/<(\\\\/?applet.??)>/si","",str); //过滤applet标签

str=pregreplace("/<(style.??)>(.??)<(\\\\/style.??)>/si","",str); //过滤style标签

str=pregreplace("/<(\\\\/?style.??)>/si","",str); //过滤style标签

str=pregreplace("/<(title.??)>(.??)<(\\\\/title.??)>/si","",str); //过滤title标签

str=pregreplace("/<(\\\\/?title.??)>/si","",str); //过滤title标签

str=pregreplace("/<(object.??)>(.??)<(\\\\/object.??)>/si","",str); //过滤object标签

str=pregreplace("/<(\\\\/?objec.??)>/si","",str); //过滤object标签

str=pregreplace("/<(noframes.??)>(.??)<(\\\\/noframes.??)>/si","",str); //过滤noframes标签

str=pregreplace("/<(\\\\/?noframes.??)>/si","",str); //过滤noframes标签

str=pregreplace("/<(i?frame.??)>(.??)<(\\\\/i?frame.??)>/si","",str); //过滤frame标签

str=pregreplace("/<(\\\\/?i?frame.??)>/si","",str); //过滤frame标签

str=pregreplace("/<(script.??)>(.??)<(\\\\/script.??)>/si","",str); //过滤script标签

str=pregreplace("/<(\\\\/?script.??)>/si","",str); //过滤script标签

str=pregreplace("/javascript/si","Javascript",str); //过滤script标签

str=pregreplace("/vbscript/si","Vbscript",str); //过滤script标签

str=pregreplace("/on([a?z] )\\\\s?=/si","On1=",str); //过滤script标签

str=preg_replace("/&#/si","&#",str); //过滤script标签,如javAsCript:alert(

str=pregreplace("/<(\\\\/?.??)>/si","",str);//匹配任意html标签方式

this?>content=pregreplace("/<(\\\\/?.??)>/si","",this->content);//过滤大多数的html标签

更多关于云服务器域名注册虚拟主机的问题,请访问西部数码官网:www.west.cn

赞(0)
声明:本网站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-62778877-8306;邮箱:fanjiao@west.cn。本站原创内容未经允许不得转载,或转载时需注明出处:西部数码知识库 » php正则替换标签的实现方法

登录

找回密码

注册