asp去掉html,保留img br p div的正则实现代码
ASP过滤HTML标签只剩<p><br><img><%FunctionReplaceContent(ContentStr)DimClsTempLoseStr,regExIfIsnull(ContentStr)OrTrim(ContentStr)=""ThenReplaceContent=""ExitFunctionEndIfContentStr=Replace(ContentStr,"<Br/>","[Br]")ContentStr=Replace(ContentStr,"<Br>","[Br]")ContentStr=Replace(ContentStr,"<P>","[P]")ContentStr=Replace(ContentStr,"</P>","[/P]")ClsTempLoseStr=Cstr(ContentStr)SetregEx=NewRegExpregEx.Pattern="<[^>]+>"regEx.IgnoreCase=TrueregEx.Global=TrueClsTempLoseStr=regEx.Replace(ClsTempLoseStr,"")ClsTempLoseStr=Replace(ClsTempLoseStr,"[Br]","<br/>")ClsTempLoseStr=Replace(ClsTempLoseStr,"[P]","<P>")ClsTempLoseStr=Replace(ClsTempLoseStr,"[/P]","</P>")ReplaceContent=ClsTempLoseStrSetregEx=NothingEndFunctionFunctionRemoveP(strText)DimRegExSetRegEx=NewRegExpRegEx.IgnoreCase=TrueRegEx.Global=TrueRegEx.Pattern="<p[^<]*(.*)[^>]*>"RemoveP=RegEx.Replace(strText,"[P]")EndFunctionFunctionRemoveImg(strText)DimRegExSetRegEx=NewRegExpRegEx.IgnoreCase=TrueRegEx.Global=TrueRegEx.Pattern="<img[^<]*src=""(.*)""[^>]*>"RemoveImg=RegEx.Replace(strText,"{imgsrc=""$1""border=0}")EndFunctionFunctionImgRemove(strText)DimRegExSetRegEx=NewRegExpRegEx.IgnoreCase=TrueRegEx.Global=TrueRegEx.Pattern="{img[^{]*src=""(.*)""[^}]*}"ImgRemove=RegEx.Replace(strText,"<imgsrc='$1'border='0'>")EndFunctionResponse.Write(ImgRemove(ReplaceContent(RemoveImg(RemoveP(html)))))%>。
2020/2/13