<% '获取内容中的图片 function GetImgSrc(str) '取得img 标签内容 dim tmp Set objRegExp = New Regexp objRegExp.IgnoreCase = True '忽略大小写 objRegExp.Global = false '全文搜索 !关键! objRegExp.Pattern = "<img (.*?)src=(.[^\[^>]*)(.*?)>" Set Matches =objRegExp.Execute(str) For Each Match in Matches tmp=tmp & Match.Value Next GetImgSrc=getimgs(tmp) end function function getimgs(str)'取得 Set objRegExp1 = New Regexp objRegExp1.IgnoreCase = True '忽略大小写 objRegExp1.Global = True '全文搜索 objRegExp1.Pattern = "src\=.+?\.(gif|jpg|png|bmp)" set mm=objRegExp1.Execute(str) For Each Match1 in mm imgsrc=Match1.Value '也许存在不能过滤的字符,确保万一 imgsrc=replace(imgsrc,"""","") imgsrc=replace(imgsrc,"src=","") imgsrc=replace(imgsrc,"<","") imgsrc=replace(imgsrc,">","") imgsrc=replace(imgsrc,"img","") imgsrc=replace(imgsrc," ","") getimgs=getimgs&imgsrc'把里面的地址串起来备用 next end function %>调用的时候直接用 <img src="<%=GetImgSrc(rs("newscontent"))%>" /> 我就没明白,直接获取<img>不是更好吗? |
<%
'***************************************************
'*函数名 : GetImgFromContent
'*参数说明 : html 被提取的html 代码
'*功能简介 : 提取这部分html代码中的图片
'*程序作者 : evio
'***************************************************
function GetImgFromContent(html)
Dim Re, match, matchs, htm, t
htm = ""
set Re = new RegExp
re.IgnoreCase =True
re.Global = True
re.Pattern = "<img [^<]*src=""(.*)""[^>]*>" '--<img [^<]*src=""(.*)""[^>]*>
Set matchs = re.Execute(html)
for each match in matchs
htm = htm + (match.SubMatches(0)) & "|$|"
next
set matchs = nothing
t = split(htm, "|$|")(0)
if len(t) = 0 or t = "" then
t = "_template_Images/prive.jpg"
end if
ze = "<img src='" & t & "' width='191' height='119' />"
end function
%>
这个没测试