asp取文章中的image图片src值
发布时间:2019-05-12

<%
'==================================================
'过程名:GetImg
'作 用:取得文章中第一张图片
'参 数:str ------ 文章内容
'参 数:strpath ------ 保存图片的路径
'==================================================

Function GetImg(str,strpath)
set objregEx = new RegExp
objregEx.IgnoreCase = true
objregEx.Global = true
zzstr=""&strpath&"(.+?)\.(jpg|gif|png|bmp)"
objregEx.Pattern = zzstr
set matches = objregEx.execute(str)
for each match in matches
retstr = retstr &"|"& Match.Value
next
if retstr<>"" then
Imglist=split(retstr,"|")
Imgone=replace(Imglist(1),strpath,"")
GetImg=Imgone
else
GetImg=""
end if
end function

但是它只能取 后缀 不能取html里的<img>所以我们需要加上正侧

Function GetImg(str)
dim objregEx,zzstr,matches,Match,retstr,Imglist,Imgone,strpath
set objregEx = new RegExp
objregEx.IgnoreCase = true
objregEx.Global = true
zzstr="<img(.+?)\.(jpg|gif|png|bmp)(.+?)>"
objregEx.Pattern = zzstr
set matches = objregEx.execute(str)
for each match in matches
retstr = retstr &"|"& Match.Value
next
if retstr<>"" then
Imglist=split(retstr,"|")
Imgone=replace(Imglist(1),strpath,"")
GetImg=Imgone
else
GetImg=""
end if
end function

调用的时候 只需要 <%=GetImg(rs("字段"))%>


%>

公司名称:六安市金狮网络技术有限公司
公司地址:安徽省六安市金安区皖西大道红叶大厦802A
联系电话:0564-3214800 手机:13956148092 邮箱:120907442@qq.com QQ:120907442 / 1099497647
手机访问