一個(gè)asp替換函數(shù)img里面多余的代碼
更新時(shí)間:2008年02月18日 21:51:23 作者:
一個(gè)asp替換函數(shù)img里面多余的代碼
<%
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不帶引號(hào)的圖片地址加上引號(hào)
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
%>
<%
'功能:返回字符串,其中指定數(shù)目的某子字符串 全部 被替換為另一個(gè)子字符串。
'來(lái)源:http://jorkin.reallydo.com/article.asp?id=406
'需要Bint函數(shù):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
%>
<%
'功能:只取數(shù)字
'來(lái)源: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不帶引號(hào)的圖片地址加上引號(hào)
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
%>
<%
'功能:返回字符串,其中指定數(shù)目的某子字符串 全部 被替換為另一個(gè)子字符串。
'來(lái)源:http://jorkin.reallydo.com/article.asp?id=406
'需要Bint函數(shù):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
%>
<%
'功能:只取數(shù)字
'來(lái)源: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
%>
相關(guān)文章
ASP UTF-8頁(yè)面亂碼+GB2312轉(zhuǎn)UTF-8 +生成UTF-8格式的文件(編碼)
ASP動(dòng)態(tài)網(wǎng)頁(yè)下UTF-8頁(yè)面亂碼+GB2312轉(zhuǎn)UTF-8 +生成UTF-8格式的文件(編碼)2008-10-10
asp中Scripting.Dictionary字典對(duì)象使用示例
這篇文章主要介紹了asp中Scripting.Dictionary字典對(duì)象使用示例,本文包含創(chuàng)建、賦值、遍歷、判斷KEY等操作,需要的朋友可以參考下2014-08-08
asp下實(shí)現(xiàn)代碼的“運(yùn)行代碼”“復(fù)制代碼”“保存代碼”功能源碼
下面的代碼是通過(guò)字符替換的方法,不是正則表達(dá)式2008-12-12
javascript增加干擾數(shù)據(jù)實(shí)現(xiàn)簡(jiǎn)單加密效果
javascript增加額外的干擾數(shù)據(jù)似簡(jiǎn)單加密,需要的朋友可以參考下。2011-01-01
JScript中調(diào)用ActiveX獲取訪客網(wǎng)卡MAC地址實(shí)現(xiàn)代碼
這篇文章主要介紹了JScript中調(diào)用ActiveX獲取訪客網(wǎng)卡MAC地址實(shí)現(xiàn)代碼,注意本文代碼只適應(yīng)運(yùn)行在IE瀏覽器上,需要的朋友可以參考下2014-08-08
用asp實(shí)現(xiàn)把文件打包成Xml文件包,帶解包的ASP工具附下載
用asp實(shí)現(xiàn)把文件打包成Xml文件包,帶解包的ASP工具附下載...2007-06-06
透徹掌握ASP分頁(yè)技術(shù)很詳細(xì)的分析
一些論壇上面關(guān)于分頁(yè)的ASP程序依然有許多的關(guān)注者,但里面只有代碼,沒(méi)有詳細(xì)的解釋?zhuān)瑢?duì)于初學(xué)者來(lái)說(shuō),這樣總是得不到真正的掌握,此次我將針對(duì)分頁(yè)技術(shù)進(jìn)行詳解,讓大家來(lái)理解ASP分頁(yè)!2008-06-06

