当前位置:asp编程网>技术教程>Asp教程>  正文

ASP获得代码中第一张图片地址

2008-12-04 21:12:00   来源:    作者:佚名   浏览量:2092   收藏
通常会做这样一个功能:在添加新闻的时候,新闻中有图片,我们需要将第一个图片取出来,保存到数据库中的另一个地方,主要是因为这个图片要用到一个独立的地方,如幻灯片或者是显示到首页。这种做法的原理是使用正则去取。
< %
'code要检测的代码
'http://www.knowsky.com/asp.asp
'leixing html 或者ubb
'nopic 代码没有图片时默认值
function toppic(code,leixing,nopic)
        set regex = new regexp
        regex.ignorecase = true
        regex.global = true
        if leixing = "html" then
                regex.pattern = "<img(.*?)src\s?\=\s?(\u0022?)([^\u0022\/>]+)"
        else
                regex.pattern = "\[img\]([^\u005B]+)“
        end if
        set matches = regex.execute(code)
        if regex.test(code) then
                                  if leixing = "html" then
                           toppic = matches(0).submatches(3)
                                  else
                                           toppic = matches(0).submatches(0)
                                  end if
        else
                toppic = nopic
        end if
end function
code1 = "<img src=""1.gif"">"
pic = toppic(code1,"html","nopic.gif")
response.Write pic
% >

关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网