欢迎光临
我们一直在努力

使用正则表达式实现模式图片新闻.ASP-ASP教程,ASP应用

建站超值云服务器,限时71元/月

文字或特定图片模式显示新闻

function shownew(content,ntype)

shownew = ""

if(ntype = 1) then

shownew = shownew &" <table width=100% >"

shownew = shownew &"<tr>"

shownew = shownew &" <td width=600 style=word-break:break-all valign=top>"&showpic(content)&"</td>"

shownew = shownew &"</tr>"

shownew = shownew &"<tr>"

shownew = shownew &" <td valign=top style=word-break:break-all>"&onlyword(content)&"</td>"

shownew = shownew &"</tr>"

shownew = shownew &"</table>"

elseif (ntype = 2) then

shownew = shownew &" <table width=100%>"

shownew = shownew &"<tr>"

shownew = shownew &" <td style=word-break:break-all valign=top>"&onlyword(content)&"</td>"

shownew = shownew &"</tr>"

shownew = shownew &"<tr>"

shownew = shownew &" <td width=600 valign=top style=word-break:break-all>"&showpic(content)&"</td>"

shownew = shownew &"</tr>"

shownew = shownew &"</table>"

elseif (ntype = 3) then

shownew = shownew &"<table>"

shownew = shownew &"<tr>"

shownew = shownew &"<td width=100 valign=top>"&showpic(content)&"</td>"

shownew = shownew &"<td width=80% style=word-break:break-all valign=top>"&onlyword(content)&"</td>"

shownew = shownew &"</tr>"

shownew = shownew &"</table>"

elseif (ntype = 4) then

shownew = shownew &"<table>"

shownew = shownew &"<tr>"

shownew = shownew &"<td width=80% valign=top style=word-break:break-all>"&onlyword(content)&"</td>"

shownew = shownew &"<td width=100 valign=top>"&showpic(content)&"</td>"

shownew = shownew &"</tr>"

shownew = shownew &"</table>"

else

shownew = shownew & "<table><tr><td style=word-break:break-all>"&content&"</td></tr></table>"

end if

end function

显示提取的图片

function showpic(strng)

showpic = ""

imageurl= regexpexecute(strng)

imageurls = split(imageurl,"<br>")

for i = lbound(imageurls) to (ubound(imageurls) – 1)

showpic = showpic & ("<a href="&imageurls(i)&" target=_blank><image src="&imageurls(i)&" border=0 alt=按此在新窗口浏览图片 onload=javascript:if(this.width>180)this.width=180></a>")

next

end function

从内容中提取图片

function regexpexecute(strng)

dim regex, match, matches 建立变量。

set regex = new regexp 建立正则表达式。

regex.pattern = "(src=)(|"&chr(34)&"| )?(.[^|\s|"&chr(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)(|"&chr(34)&"|\s|>)?" 设置模式。

regex.pattern = "(src=)(|"&chr(34)&"| )?(.[^| |"&chr(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)(|"&chr(34)&"| |>)?" 设置模式。

regex.pattern = "(s|s)(r|r)(c|c)=(|"+chr(34)+")(\w|\\|\/|\.)+(|"+chr(34)+"| *|>)?" 设置模式。

regex.ignorecase = true 设置是否区分字符大小写。

regex.global = true 设置全局可用性。

set matches = regex.execute(strng) 执行搜索。

for each match in matches 遍历匹配集合。

values=values&match.submatches(2)&match.submatches(3)&match.submatches(4)&"<br>"

next

regexpexecute = values

end function

删除内容中与图片有关的代码

function onlyword(strng)

set re=new regexp

re.ignorecase =true

re.global=true

re.pattern = "(<)(.[^<]*)(src=)(|"&chr(34)&"| )?(.[^|\s|"&chr(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)(|"&chr(34)&"|\s|>)(.[^>]*)(>)" 设置模式。

onlyword=re.replace(strng,"")

set re= nothing

end function

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用正则表达式实现模式图片新闻.ASP-ASP教程,ASP应用
分享到: 更多 (0)