asp网站如何把内容里的<p style="...">替换为<p>,同时保留img标签呢?
我想要把类似<pstyle="......"></p>这样的标签,都替换为<p></p>去掉样式表,asp代码的正则表达式怎么写呢,求助!...
我想要把类似
<p style="......"></p>
这样的标签,都替换为<p></p>
去掉样式表,asp代码的正则表达式怎么写呢,求助! 展开
<p style="......"></p>
这样的标签,都替换为<p></p>
去掉样式表,asp代码的正则表达式怎么写呢,求助! 展开
1个回答
展开全部
'用法 RHtml=SimpleHTML(html,"p,img,a,span")
Function SimpleHTML(content,tags)
If tags="" Then tags="p,br"
SimpleHTML = RegReplace("<(\/?)("& Replace(tags,",","|") &")([^>]*)>",content&"","[$1$2$3]")
SimpleHTML = RegReplace("<[^>]*>",SimpleHTML,"")
SimpleHTML = RegReplace("\[(\/?)("& Replace(tags,",","|") &")([^\]]*)\]",SimpleHTML,"<$1$2$3>")
End Function
'生成一个正则表达式对象
Function REObject( reg, m)
Dim re:Set re=new RegExp
re.Pattern = reg
If InStr(1, m, "g", 1)>0 Then re.Global = True
If InStr(1, m, "i", 1)>0 Then re.IgnoreCase = True
If InStr(1, m, "m", 1)>0 Then re.MultiLine = True
Set REObject=re
End Function
Function RegReplace( reg, str, rstr)
RegReplace=RegExpReplace(reg,"ig",str,rstr)
End Function
'正则替换字符串
Function RegExpReplace( reg, m, str, rstr)
RegExpReplace=REObject(reg, m).Replace(str,rstr)
End Function
后面几个是用到的函数
会将html代码中非指定的标签全部去除,如果要去除标签内的属性,需要修改下simplehtml这个函数,把$3去掉
Function SimpleHTML(content,tags)
If tags="" Then tags="p,br"
SimpleHTML = RegReplace("<(\/?)("& Replace(tags,",","|") &")([^>]*)>",content&"","[$1$2$3]")
SimpleHTML = RegReplace("<[^>]*>",SimpleHTML,"")
SimpleHTML = RegReplace("\[(\/?)("& Replace(tags,",","|") &")([^\]]*)\]",SimpleHTML,"<$1$2>")
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询