客户要求保存原有的img已在的属性,郁闷,继续改
代码如下:
function shownew(content,ntype)
shownew = ""
if(ntype = 1) then
shownew = shownew &" <table width=100% >"
shownew = shownew &"<tr>"
shownew = shownew &" <td width=700 align=center style=word-break:break-all valign=top>"&showpic(content)&"</td>"
shownew = shownew &"</tr>"
shownew = shownew &"<tr>"
shownew = shownew &" <td valign=top style=word-break:break-all>"&onlyword(content)&"</td>"
shownew = shownew &"</tr>"
shownew = shownew &"</table>"
elseif (ntype = 2) then
shownew = shownew &" <table width=100%>"
shownew = shownew &"<tr>"
shownew = shownew &" <td style=word-break:break-all valign=top>"&onlyword(content)&"</td>"
shownew = shownew &"</tr>"
shownew = shownew &"<tr>"
shownew = shownew &" <td align=center width=700 valign=top style=word-break:break-all>"&showpic(content)&"</td>"
shownew = shownew &"</tr>"
shownew = shownew &"</table>"
elseif (ntype = 3) then
shownew = shownew &"<table>"
shownew = shownew &"<tr>"
shownew = shownew &"<td width=100 align=center valign=top>"&showpic(content)&"</td>"
shownew = shownew &"<td width=80% style=word-break:break-all valign=top>"&onlyword(content)&"</td>"
shownew = shownew &"</tr>"
shownew = shownew &"</table>"
elseif (ntype = 4) then
shownew = shownew &"<table>"
shownew = shownew &"<tr>"
shownew = shownew &"<td width=80% valign=top style=word-break:break-all>"&onlyword(content)&"</td>"
shownew = shownew &"<td width=100 valign=top align=center>"&showpic(content)&"</td>"
shownew = shownew &"</tr>"
shownew = shownew &"</table>"
else
shownew = shownew &content
end if
end function
显示提取的图片
function showpic(strng)
set regex2 = new regexp
regex2.pattern = "(src=)(|"&chr(34)&"| )?(.[^| |"&chr(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)(|"&chr(34)&"| |>)?" 设置模式。
regex2.ignorecase = true 设置是否区分字符大小写。
regex2.global = true 设置全局可用性。
showpic = ""
imageurl= regexpexecute(strng)
imageurls = split(imageurl,"{|ldiv|}")
for i = lbound(imageurls) to (ubound(imageurls) – 1)
set matches2 = regex2.execute(imageurls(i)) 执行搜索。
for each match2 in matches2 遍历匹配集合。
全img标签
newpic = lcase(imageurls(i))
如果没有自定义border增加border=0,其它原属性保留
if(instr(newpic,"border")=false) then newpic = left(newpic,len(newpic)-1) + " border=0 >"
if(instr(newpic,"width")=false) then newpic = left(newpic,len(newpic)-1) + " width=200 >"
newpic = "<a style=padding:20px href="&match2.submatches(2)&match2.submatches(3)&match2.submatches(4)&" >"& newpic & "</a>"
showpic = showpic & newpic
next
next
set regex2 = nothing
end function
从内容中提取图片
function regexpexecute(strng)
dim regex, match, matches 建立变量。
set regex = new regexp 建立正则表达式。
regex.pattern = "(<)(.[^<]*)(src=)(|"&chr(34)&"| )?(.[^|\s|"&chr(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)(|"&chr(34)&"|\s|>)(.[^>]*)(>)" 设置模式。
regex.ignorecase = true 设置是否区分字符大小写。
regex.global = true 设置全局可用性。
set matches = regex.execute(strng) 执行搜索。
for each match in matches 遍历匹配集合。
values=values&match.value&"{|ldiv|}"
next
regexpexecute = values
end function
删除内容中与图片有关的代码
function onlyword(strng)
set re=new regexp
re.ignorecase =true
re.global=true
re.pattern = "(<)(.[^<]*)(src=)(|"&chr(34)&"| )?(.[^|\s|"&chr(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)(|"&chr(34)&"|\s|>)(.[^>]*)(>)" 设置模式。
onlyword=re.replace(strng,"")
set re= nothing
end function