一个asp替换函数img里面多余的代码
2023-06-13 09:13:59 时间
<%
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
%>
<%
"功能:返回字符串,其中指定数目的某子字符串 全部 被替换为另一个子字符串。
"来源:http://jorkin.reallydo.com/article.asp?id=406
"需要Bint函数:http://jorkin.reallydo.com/article.asp?id=395
Function ReplaceAll(sExpression, sFind, sReplaceWith, bAll)
If IsNull(sExpression) Then ReplaceAll = "" : Exit Function
If (StrComp(bAll, "True", 1) = 0) Or (CBool(Bint(bAll)) = True) Then
Do While InStr( 1, sExpression, sFind, 1) > 0
sExpression = Replace(sExpression, sFind, sReplaceWith, 1, -1, 1)
If InStr( 1, sReplaceWith , sFind , 1) >0 Then Exit Do
Loop
Else
Do While InStr(sExpression, sFind) > 0
sExpression = Replace(sExpression, sFind, sReplaceWith)
If InStr(sReplaceWith, sFind ) > 0 Then Exit Do
Loop
End If
ReplaceAll = sExpression
End Function
%>
<%
"功能:只取数字
"来源:http://jorkin.reallydo.com/article.asp?id=395
Function Bint(Str)
Str = Trim(Str)
If Str = "" Or IsNull(Str) Or Not IsNumeric(Str) Then Str = "0"
Bint = Round(Str, 0)
End Function
%>
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
%>
<%
"功能:返回字符串,其中指定数目的某子字符串 全部 被替换为另一个子字符串。
"来源:http://jorkin.reallydo.com/article.asp?id=406
"需要Bint函数:http://jorkin.reallydo.com/article.asp?id=395
Function ReplaceAll(sExpression, sFind, sReplaceWith, bAll)
If IsNull(sExpression) Then ReplaceAll = "" : Exit Function
If (StrComp(bAll, "True", 1) = 0) Or (CBool(Bint(bAll)) = True) Then
Do While InStr( 1, sExpression, sFind, 1) > 0
sExpression = Replace(sExpression, sFind, sReplaceWith, 1, -1, 1)
If InStr( 1, sReplaceWith , sFind , 1) >0 Then Exit Do
Loop
Else
Do While InStr(sExpression, sFind) > 0
sExpression = Replace(sExpression, sFind, sReplaceWith)
If InStr(sReplaceWith, sFind ) > 0 Then Exit Do
Loop
End If
ReplaceAll = sExpression
End Function
%>
<%
"功能:只取数字
"来源:http://jorkin.reallydo.com/article.asp?id=395
Function Bint(Str)
Str = Trim(Str)
If Str = "" Or IsNull(Str) Or Not IsNumeric(Str) Then Str = "0"
Bint = Round(Str, 0)
End Function
%>
相关文章
- 快速搭建ASP应用MySQL配置指南(asp配置mysql)
- ASP连接MySQL编码入门实战(asp链接mysql代码)
- ASP读取MySQL数据库操作变慢的原因分析(asp+读取mysql慢)
- ASP如何使用代码登录MySQL数据库(asp登陆mysql代码)
- 从ASP到MySQL改进你的代码(asp改MySQL代码)
- 数据如何使用ASP操作MySQL数据库(asp怎么存取mysql)
- 优雅地实现 ASP配置 Oracle 数据库(asp配置oracle)
- ASP代码的对象化
- asp的分词实现代码
- asp快速开发方法之数据操作实例代码
- ReSaveRemoteFile函数之asp实现查找文件保存替换的代码
- CheckFile函数之asp实现检查某一文件是否存在的代码
- asp.net中将表单提交到另一页Code-Behind(代码和html在不同的页面)
- Asp编码互转的研究和实现代码
- asp.ne去除html的函数代码
- asp.nettextarea换行函数代码
- asp网站静态化函数代码html
- ASP与Excel结合生成数据表和Chart图的代码
- Asp返回引用类型函数代码
- asp下过滤非法的SQL字符的函数代码
- asp.net上传图片保存到数据库的代码
- asp中格式化HTML函数代码SDCMS加强版
- ASP使用Filter函数来检索数组的实现代码
- ASP调用远程XML数据的代码(alexa排名数据)
- asp获取参数值与sql安全过滤参数函数代码
- asp.net网站底部的版权信息实现代码且可维护
- 做了CDN获取用户真实IP的函数代码(PHP与Asp设置方式)
- asp.net导出Excel类库代码分享
- asp实现的sha1加密解密代码(和C#兼容)