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

2016-01-29 18:53 8 1 收藏

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

【 tulaoshi.com - ASP 】

 

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

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"

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/asp/)

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)

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/asp/)

 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="http://img.jcwcn.com/attachment/portal"&ImageUrls(i)&"' border='0' alt='按此在新窗口浏览图片' onload='javascript:if(this.width180)this.width=180'</a")

    next
 
end function


'从内容中提取图片
Function RegExpExecute(strng)
    Dim regEx, Match, Matches '建立变量。
    Set regEx = New RegExp '建立正则表达式。
      regEx.Pattern = "(src="http://img.jcwcn.com/attachment/portal"&CHR(34)&"| )?(.[^'|s|"&CHR(34)&"]*)(.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"|s|)?" '设置模式。
   ' regEx.Pattern = "(src="http://img.jcwcn.com/attachment/portal"&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 =Tru

来源:https://www.tulaoshi.com/n/20160129/1507643.html

延伸阅读
标签: PHP
如果我们问那些UNIX系统的爱好者他们最喜欢什么,答案除了稳定的系统和可以远程启动之外,十有八九的人会提到正则表达式;如果我们再问他们最头痛的是什么,可能除了复杂的进程控制和安装过程之外,还会是正则表达式。那么正则表达式到底是什么?如何才能真正的掌握正则表达式并正确的加以灵活运用?本文将就此展开介绍,希...
标签: Web开发
如果我们问那些UNIX系统的爱好者他们最喜欢什么,答案除了稳定的系统和可以远程启动之外,十有八九的人会提到正则表达式;如果我们再问他们最头痛的是什么,可能除了复杂的进程控制和安装过程之外,还会是正则表达式。那么正则表达式到底是什么?如何才能真正的掌握正则表达式并正确的加以灵活运用?本文将就此展开介绍,希望能够对那些渴...
标签: PHP
在对正则表达式有了较为全面的了解之后,我们就来看一下如何在Perl,PHP,以及JavaScript/" target="_blank"JavaScript中使用正则表达式。 通常,Perl中正则表达式的使用格式如下: operator / regular-expression / string-to-replace / modifiers 运算符一项可以是m或s,分别代表匹配运算和替换...
标签: Web开发
正则表达式是一种文本模式,包括普通字符(例如,a 到 z 之间的字母)和特殊字符(称为元字符)。模式描述在搜索文本时要匹配的一个或多个字符串。   正则表达式示例 表达式 匹配 /^\s*$/ 匹配空行。 /\d{2}-\d{5}/ 验证由两位数字、一个连字符再加 5 位数字组成的 ID 号。 /\s*(\S+)(\s[^]*)?[\s\S]*\s*\/\1\s*/ ...
标签: Web开发
正则表达式在PHP中被用来处理复杂的文字串。支持正则表达式的函数有: ereg()ereg replace()eregi replace()split() 这些函数都将正则表达式作为他们的第一个参数。PHP使用POSIX扩展规则表达式(使用POSIX 1003.2)。要找到所有的关于POSIX扩展规则表达式的描述,请查看包括在PHP发行版本之内的regex man页面。 Examp...

经验教程

835

收藏

37
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部