直接用正则替换,但没有判断功能
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"" 在新窗口中打开浏览"" 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
<% content2="<img src='https://www.zzaxw.com/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)="https://www.zzaxw.com" then picurl=tmpurl else picurl="http://img.123.net/showpic.asp?url="&tmpurl end if Content=replace(Content2,strMatch.Value,"<img src="&picurl&" style=""cursor: pointer"" 在新窗口中打开浏览"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>") Next response.write Content set re = nothing %>
© 版权声明
本文刊载的所有内容,包括文字、图片、音频、视频、软件、程序、以及网页版式设计等部门来源于互联网,版权均归原作者所有!本网站提供的内容服务于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯本网站及相关权利人的合法权利。
联系信息:邮箱aoxolcom@163.com或见网站底部。
联系信息:邮箱aoxolcom@163.com或见网站底部。
THE END
请登录后发表评论
注册
社交帐号登录