一个asp替换函数img里面多余的代码
一个asp替换函数img里面多余的代码
发布时间:2016-12-29 来源:查字典编辑
摘要:

<%

Response.Write(Server.HTMLEncode(FixImg("<imgonclick=""if(this.width>screen.width-461)window.open('qq/20082181405371.jpg');""alt=""""border=""0""src=""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

%>

<%

'功能:返回字符串,其中指定数目的某子字符串全部被替换为另一个子字符串。

'来源:http://jorkin.reallydo.com/article.asp?id=406

'需要Bint函数:http://jorkin.reallydo.com/article.asp?id=395

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

%>

<%

'功能:只取数字

'来源:http://jorkin.reallydo.com/article.asp?id=395

FunctionBint(Str)

Str=Trim(Str)

IfStr=""OrIsNull(Str)OrNotIsNumeric(Str)ThenStr="0"

Bint=Round(Str,0)

EndFunction

%>

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ASP教程学习
热门ASP教程学习
编程开发子分类