芜湖网站建设芜湖网站优化、模板建站、微信小程序开发的网站定制服务由芜湖芝麻开门网络科技有限公司为您服务。
建站电话

0553-7552712

asp去掉html,保留img br p div的正则实现代码

标签:芜湖网站建设 2020/2/13 

ASP 过滤HTML标签只剩<p> <br> <img>

<%

Function ReplaceContent(ContentStr)

Dim ClsTempLoseStr,regEx

If Isnull(ContentStr) Or Trim(ContentStr)="" Then

ReplaceContent=""

Exit Function

End If

ContentStr = Replace(ContentStr, "<Br />", "[Br]")

ContentStr = Replace(ContentStr, "<Br>", "[Br]")

ContentStr = Replace(ContentStr, "<P>", "[P]")

ContentStr = Replace(ContentStr, "</P>", "[/P]")

ClsTempLoseStr = Cstr(ContentStr)

Set regEx = New RegExp

regEx.Pattern = "<[^>]+>"

regEx.IgnoreCase = True

regEx.Global = True

ClsTempLoseStr = regEx.Replace(ClsTempLoseStr,"")

ClsTempLoseStr = Replace(ClsTempLoseStr, "[Br]", "<br />")

ClsTempLoseStr = Replace(ClsTempLoseStr, "[P]", "<P>")

ClsTempLoseStr = Replace(ClsTempLoseStr, "[/P]", "</P>")

ReplaceContent = ClsTempLoseStr

Set regEx = Nothing

End Function

Function RemoveP(strText)

Dim RegEx

Set RegEx=New RegExp

RegEx.IgnoreCase=True

RegEx.Global=True

RegEx.Pattern="<p [^<]*(.*)[^>]*>"

RemoveP=RegEx.Replace(strText,"[P]")

End Function

Function RemoveImg(strText)

Dim RegEx

Set RegEx=New RegExp

RegEx.IgnoreCase=True

RegEx.Global=True

RegEx.Pattern="<img [^<]*src=""(.*)""[^>]*>"

RemoveImg=RegEx.Replace(strText,"{img src=""$1"" border=0}")

End Function

Function ImgRemove(strText)

Dim RegEx

Set RegEx=New RegExp

RegEx.IgnoreCase=True

RegEx.Global=True

RegEx.Pattern="{img [^{]*src=""(.*)""[^}]*}"

ImgRemove=RegEx.Replace(strText,"<img src='$1' border='0'>")

End Function

Response.Write(ImgRemove(ReplaceContent(RemoveImg(RemoveP(html)))))

%>