使用正则表达式实现模式图片新闻.ASP
2008-02-23 05:30:52来源:互联网 阅读 ()
'文字或特定图片模式显示新闻
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
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:动态网站首页的静态生成方法
下一篇:让你的WAP网站有更好的兼容性
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash