一个asp替换函数img里面多余的代码
程序员文章站
2022-06-05 09:12:03
<% response.write(server.htmlencode(fiximg("
<%
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
%>
上一篇: 文件名 正则表达式提取方法
下一篇: 红糖的坏处你都知道吗