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

发布时间:2023-09-21 点击:141
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标签

腾讯云服务器配置ftp服务
这个域名打不开-虚拟主机/数据库问题
万根云服务器网站相关云计算内容
广州ecs云服务器硬盘空间
阿里云服务器能备案多少主题
word一打字后面的字就没了如何处理_word打字后面的字消失了的解决教程
网站打不开了后台调整幻灯片的时候选错了
seo优化文章怎么写能满足用户搜索需求