一個asp替換函數img裡面多餘的代碼

來源:互聯網
上載者:User

<%
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
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.