Asp从一段内容中获取第一张图片的地址
2009-04-16 10:39:15 来源:WEB开发网<%
str="<img src=http://www.cncms.com/images/200610261533.jpg><img src=""http://www.cncms.com/images/200609151656.jpg""><img src=http://www.cncms.com/images/200609051735.JPG>"
response.write(GetImgSrc(str))
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
%>
更多精彩
赞助商链接