一个asp替代函数img里面多余的代码
发布时间:2023-11-25 12:15:39 所属栏目:Asp教程 来源:
导读:<%
Response.Write(Server.HTMLEncode(FixImg("<img onclick=""if(this.width>screen.width-461) window.open('qq/20082181405371.jpg');"" alt="""" border=""0"" src="&
Response.Write(Server.HTMLEncode(FixImg("<img onclick=""if(this.width>screen.width-461) window.open('qq/20082181405371.jpg');"" alt="""" border=""0"" src="&
<% Response.Write(Server.HTMLEncode(FixImg("<img onclick=""if(this.width>screen.width-461) window.open('qq/20082181405371.jpg');"" alt="""" border=""0"" src=""qq/20082181405371.jpg"" />"))) %> <% '功能:将IMG代码格式化为<img src="XXX" />格式. Function FixImg(sString) Dim sReallyDo, regEx, iReallyDo Dim oMatches, cMatch Dim tStartTime, tEndTime If IsNull(sString) Then FixImg = "" Exit Function End If sReallyDo = sString On Error Resume Next sReallyDo = Replace(sReallyDo, vbCr, " ") sReallyDo = Replace(sReallyDo, vbLf, " ") sReallyDo = Replace(sReallyDo, vbTab, " ") sReallyDo = Replace(sReallyDo, "<img ", vbCrLf & "<img ", 1, -1, 1) sReallyDo = Replace(sReallyDo, "/>", " />", 1, -1, 1) sReallyDo = ReplaceAll(sReallyDo, "= ", "=", True) sReallyDo = ReplaceAll(sReallyDo, "> ", ">", True) sReallyDo = Replace(sReallyDo, "><", ">" & vbCrLf & "<") sReallyDo = Trim(sReallyDo) On Error GoTo 0 Set regEx = New RegExp regEx.IgnoreCase = True regEx.Global = True '//去除onclick,onload等脚本 regEx.Pattern = "/s[on].+?=([/""|/'])(.*?)/1" sReallyDo = regEx.Replace(sReallyDo, "") '//将SRC不带引号的图片地址加上引号 regEx.Pattern = "<img.*?/ssrc=([^/""/'/s][^/""/'/s>]*).*?>" sReallyDo = regEx.Replace(sReallyDo, "<img src=""$1"" />") '//正则匹配图片SRC地址 regEx.Pattern = "<img.*?/ssrc=([/""/'])([^/""/']+?)/1.*?>" sReallyDo = regEx.Replace(sReallyDo, "<img src=""$2"" />") FixImg = sReallyDo End Function (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐