一个asp替换函数img里面多余的代码
2018-09-06 11:39
<%
Response.Write(Server.HTMLEncode(FixImg(<imgonclick=if(this.width>screen.width-461)window.open(qq/20082181405371.jpg);alt=border=0src=qq/20082181405371.jpg/>)))
%>
<%
功能:将IMG代码格式化为<imgsrc=XXX/>格式.
FunctionFixImg(sString)
DimsReallyDo,regEx,iReallyDo
DimoMatches,cMatch
DimtStartTime,tEndTime
IfIsNull(sString)Then
FixImg=
ExitFunction
EndIf
sReallyDo=sString
OnErrorResumeNext
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)
OnErrorGoTo0
SetregEx=NewRegExp
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,<imgsrc=$1/>)
//正则匹配图片SRC地址
regEx.Pattern=<img.*?\ssrc=([\\])([^\\]+?)\1.*?>
sReallyDo=regEx.Replace(sReallyDo,<imgsrc=$2/>)
FixImg=sReallyDo
EndFunction
%>
<%
功能:返回字符串,其中指定数目的某子字符串全部被替换为另一个子字符串。
来源:
需要Bint函数:
FunctionReplaceAll(sExpression,sFind,sReplaceWith,bAll)
IfIsNull(sExpression)ThenReplaceAll=:ExitFunction
If(StrComp(bAll,True,1)=0)Or(CBool(Bint(bAll))=True)Then
DoWhileInStr(1,sExpression,sFind,1)>0
sExpression=Replace(sExpression,sFind,sReplaceWith,1,-1,1)
IfInStr(1,sReplaceWith,sFind,1)>0ThenExitDo
Loop
Else
DoWhileInStr(sExpression,sFind)>0
sExpression=Replace(sExpression,sFind,sReplaceWith)
IfInStr(sReplaceWith,sFind)>0ThenExitDo
Loop
EndIf
ReplaceAll=sExpression
EndFunction
%>
<%
功能:只取数字
来源:
FunctionBint(Str)
Str=Trim(Str)
IfStr=OrIsNull(Str)OrNotIsNumeric(Str)ThenStr=0
Bint=Round(Str,0)
EndFunction
%>
上一篇:小偷小偷入库采集入库
下一篇:asp中Recordset的属性
文章标题:一个asp替换函数img里面多余的代码
文章链接:http://soscw.com/index.php/essay/9595.html