zoukankan      html  css  js  c++  java
  • asp 图片正则 替换,替换前检查图片是不是本地地址的方法

    这个图片正则先检查图片的地址,不是本地的则用本地的asp突破盗链,方便使用
    直接用正则替换,但没有判断功能
    Function FormatImg(content)
    dim re
    Set re=new RegExp
    re.IgnoreCase =true
    re.Global=True
    re.Pattern="(script)"
    Content=re.Replace(Content,"script")
    re.Pattern="<img.[^>]*src(=| )(.[^>]*)>"
    Content=re.replace(Content,"<img src=$2 style=""cursor: pointer"" alt=""在新窗口中打开浏览"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")
    set re = nothing
    FormatImg = content
    End Function
    这段代码将内容中的图片替换成 <img src=$2 style="cursor: pointer" alt="在新窗口中打开浏览" onclick="javascript:window.open(this.src);" onload="javascript:resizepic(this)" border="0"/> 这中形式的,
    我现在需要提取$2的前7个字符,用来判断是否需要被替换,如果前7=特定的字符,就不要替换,但获取$2的前7 无法。大家有什么办法支下招撒?
    主要是参考了下面的代码,大家可以看下
    '连接
    re.Pattern = "/[url=(.[^/]]*)/](.[^/[]*)/[//url]"
    Set strMatchs=re.Execute(strContent)
    For Each strMatch in strMatchs
    tmpStr1=checkURL(strMatch.SubMatches(0))
    tmpStr2=strMatch.SubMatches(1)
    strContent=replace(strContent,strMatch.Value,"<a target=""_blank"" href="""&tmpStr1&""">"&tmpStr2&"</a>",1,-1,0)
    Next
    这里是正则的Matchs的说明文档
    http://www.jb51.net/article/15362.htm
    下面由脚本之家测试代码,大家可以做出函数
    <%
    content2="<img src='http://www.jb51.net/images/logo.gif' width=100 />中间一些内容<img src='http://www.kanshule.com/indeximg/logo.GIF' width=200 />"
    dim re
    Set re=new RegExp
    re.IgnoreCase =true
    re.Global=True
    re.Pattern="<img.[^>]*src(=| )(.[^>]*)[/]?>"
    set Matches=re.execute(content2)
    For Each strMatch in Matches
    tmpStr1=(strMatch.SubMatches(1))
    tmpurl=replace(replace(tmpStr1,"'",""),"""","")
    //response.write left(tmpurl,20)
    if left(tmpurl,19)="http://www.jb51.net" then
    picurl=tmpurl
    else
    picurl="http://img.jb51.net/showpic.asp?url="&tmpurl
    end if
    Content=replace(Content2,strMatch.Value,"<img src="&picurl&" style=""cursor: pointer"" alt=""在新窗口中打开浏览"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")
    Next
    response.write Content
    set re = nothing
    %>
    http://www.corange.cn/archives/2008/11/2239.html

  • 相关阅读:
    每日立会2015-11-30
    Some Modern Softwares' drawbacks: User experience 12/29/2015
    Sprint 5 summary: UI 界面更新,Azure端部署和用户反馈分析 12/28/2015
    Daily Scrum 12/25/2015
    Daily Scrum 12/24/2015
    Daily Scrum 12/23/2015
    Daily Scrum 12/21/2015
    Daily Scrum 12/18/2015
    Daily Scrum 12/17/2015
    Performance standard (ALPHA release) 12/17/2015
  • 原文地址:https://www.cnblogs.com/zerogo/p/2209108.html
Copyright © 2011-2022 走看看