使用正则表达式实现模式图片新闻.ASP

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

function shownew(content,ntype)

shownew = ""

if(ntype = 1) then

shownew = shownew &"

1<table width="100%">"   
2shownew = shownew &amp;"<tr>"   
3shownew = shownew &amp;" <td style="word-break:break-all" valign="top" width="600">"&amp;ShowPic(content)&amp;"</td>"   
4shownew = shownew &amp;"</tr>"   
5shownew = shownew &amp;"<tr>"   
6shownew = shownew &amp;" <td style="word-break:break-all" valign="top">"&amp;OnlyWord(content)&amp;"</td>"   
7shownew = shownew &amp;"</tr>"   
8shownew = shownew &amp;"</table>

"

elseif (ntype = 2) then

shownew = shownew &"

1<table width="100%">" 
2
3shownew = shownew &amp;"<tr>"   
4shownew = shownew &amp;" <td style="word-break:break-all" valign="top">"&amp;OnlyWord(content)&amp;"</td>"   
5shownew = shownew &amp;"</tr>"   
6shownew = shownew &amp;"<tr>"   
7shownew = shownew &amp;" <td style="word-break:break-all" valign="top" width="600">"&amp;ShowPic(content)&amp;"</td>"   
8shownew = shownew &amp;"</tr>"   
9shownew = shownew &amp;"</table>

"

elseif (ntype = 3) then

shownew = shownew &"

 1<table>" 
 2
 3shownew = shownew &amp;"<tr>"   
 4shownew = shownew &amp;"<td valign="top" width="100">"&amp;ShowPic(content)&amp;"</td>" 
 5
 6shownew = shownew &amp;"<td style="word-break:break-all" valign="top" width="80%">"&amp;OnlyWord(content)&amp;"</td>" 
 7
 8  
 9shownew = shownew &amp;"</tr>"   
10shownew = shownew &amp;"</table>

"

elseif (ntype = 4) then

shownew = shownew &"

1<table>" 
2
3shownew = shownew &amp;"<tr>" 
4
5shownew = shownew &amp;"<td style="word-break:break-all" valign="top" width="80%">"&amp;OnlyWord(content)&amp;"</td>"   
6shownew = shownew &amp;"<td valign="top" width="100">"&amp;ShowPic(content)&amp;"</td>" 
7
8shownew = shownew &amp;"</tr>"   
9shownew = shownew &amp;"</table>

"
else
shownew = shownew & "

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

"
end if

end function

'显示提取的图片
function ShowPic(strng)

ShowPic = ""
ImageUrl= RegExpExecute(strng)

ImageUrls = Split(ImageUrl,"

1<br/>

")

for i = LBound(ImageUrls) to (UBound(ImageUrls) - 1)

ShowPic = ShowPic & ("

1<a href='"&amp;ImageUrls(i)&amp;"' target="_blank"><image alt="按此在新窗口浏览图片" border="0" onload="javascript:if(this.width&gt;180)this.width=180" src='"&amp;ImageUrls(i)&amp;"'/></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)&"

1<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

Published At
Categories with Web编程
Tagged with
comments powered by Disqus