ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
使用正则表达式实现模式图片新闻(加强).ASP

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

客户要求保存原有的img已在的属性,郁闷,继续改

代码如下:


function shownew(content,ntype)

shownew = ""

if(ntype = 1) then

shownew = shownew &" <TABLE width=100% >"
shownew = shownew &"<TR>"
shownew = shownew &" <TD width=700 align=center 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  align=center width=700 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 align=center 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 align=center>"&ShowPic(content)&"</TD>"

shownew = shownew &"</TR>"
shownew = shownew &"</TABLE>"
else
 shownew = shownew &content
end if

end function

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

 set regEx2  = new RegExp

 regEx2.Pattern = "(src=)('|"&CHR(34)&"| )?(.[^'| |"&CHR(34)&"]*)(\.)(jpg|gif|png|bmp|jpeg)('|"&CHR(34)&"| |>)?" '设置模式。
    regEx2.IgnoreCase = true '设置是否区分字符大小写。
    regEx2.Global = True '设置全局可用性。
 
 ShowPic = ""
 ImageUrl= RegExpExecute(strng)

 ImageUrls = Split(ImageUrl,"{|LDIV|}")


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


   Set Matches2 = regEx2.Execute(ImageUrls(i)) '执行搜索。

   For Each Match2 in Matches2 '遍历匹配集合。

     '全Img标签
     newpic = LCase(ImageUrls(i))

     '如果没有自定义BORDER增加BOrder=0,其它原属性保留

      if(instr(newpic,"border")=false) then newpic =  left(newpic,len(newpic)-1) + " border='0' >"
      if(instr(newpic,"width")=false) then newpic =  left(newpic,len(newpic)-1) + "  width='200'  >"

     newpic = "<a style='padding:20px' href='"&Match2.SubMatches(2)&Match2.SubMatches(3)&Match2.SubMatches(4)&"' >"& newpic & "</a>"

    ShowPic  = ShowPic & newpic
   Next


    next

 Set regEx2 = nothing
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.IgnoreCase = true '设置是否区分字符大小写。
    regEx.Global = True '设置全局可用性。
    Set Matches = regEx.Execute(strng) '执行搜索。
    For Each Match in Matches '遍历匹配集合。
       values=values&Match.Value&"{|LDIV|}"
    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




相关文章

相关软件