欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp 圖片正則 替換,替換前檢查圖片是不是本地地址的方法

 更新時(shí)間:2008年08月03日 15:55:41   作者:  
這個(gè)圖片正則先檢查圖片的地址,不是本地的則用本地的asp突破盜鏈,方便使用,注意是答chinaz的朋友問(wèn)的一個(gè)問(wèn)題
直接用正則替換,但沒(méi)有判斷功能
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=""在新窗口中打開(kāi)瀏覽"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")
set re = nothing
FormatImg = content
End Function
這段代碼將內(nèi)容中的圖片替換成 <img src=$2 style="cursor: pointer" alt="在新窗口中打開(kāi)瀏覽" onclick="javascript:window.open(this.src);" onload="javascript:resizepic(this)" border="0"/> 這中形式的,
我現(xiàn)在需要提取$2的前7個(gè)字符,用來(lái)判斷是否需要被替換,如果前7=特定的字符,就不要替換,但獲取$2的前7 無(wú)法。大家有什么辦法支下招撒? 

主要是參考了下面的代碼,大家可以看下
'連接
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的說(shuō)明文檔
http://www.dbjr.com.cn/article/15362.htm

下面由腳本之家測(cè)試代碼,大家可以做出函數(shù)
<%
content2="<img src='http://www.dbjr.com.cn/images/logo.gif' width=100 />中間一些內(nèi)容<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.dbjr.com.cn" 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=""在新窗口中打開(kāi)瀏覽"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")
Next
response.write Content
set re = nothing

%>

相關(guān)文章

最新評(píng)論