程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> ASP技巧 >> 使用正則表達式實現模式圖片新聞.ASP

使用正則表達式實現模式圖片新聞.ASP

編輯: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>"

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

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved