UBB

1.UBB的保存。直接保存,通过javascript,以UBB格式直接保存在数据库里。关键问题要过滤掉不安全代码。
例如:
None.gif          public   string  Filtrate( string  content)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
if(content == null)
InBlock.gif                
return "";
InBlock.gif            content 
= content.Replace("<"," ");
InBlock.gif            content 
= content.Replace(">"," ");
InBlock.gif            
return(content);    
ExpandedBlockEnd.gif        }

2.UBB的显示。
None.gif using  System;
None.gif
using  System.Text;
None.gif
using  System.Text.RegularExpressions;
None.gif
None.gif
namespace  UBB
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary> 
InBlock.gif    
/// 功能:UBB代码
InBlock.gif    
/// 作者:小迪
InBlock.gif    
/// 日期:2005-3-20
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class UBB
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ContractedSubBlock.gifExpandedSubBlockStart.gif        
构造函数#region 构造函数
InBlock.gif        
public UBB()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// TODO: 在此处添加构造函数逻辑
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
UBBToHTML#region UBBToHTML
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// UBB代码处理函数
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="detail">输入字符串</param>
ExpandedSubBlockEnd.gif        
/// <returns>输出字符串</returns>

InBlock.gif        public string UBBToHTML(string detail)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Regex r;
InBlock.gif            Match m;
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[em]标记,处理心情图标#region 处理[em]标记,处理心情图标 
InBlock.gif            
string EmotPath="BBS/Skins/Default/emot/";        //路径可更改,图片名以em开头
InBlock.gif
            detail = Regex.Replace(detail,@"\[em(.[^\[]*)\]",@"<img src="+EmotPath+"em$1.gif border=0 align=middle>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理html标记#region 处理html标记
InBlock.gif            detail 
= detail.Replace("<","&lt;");
InBlock.gif            detail 
= detail.Replace(">","&gt;");
InBlock.gif            detail 
= detail.Replace("'","''"); 
ExpandedSubBlockEnd.gif            
#endregion
            
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理空格#region 处理空格
InBlock.gif            detail 
= detail.Replace(" ","&nbsp;");
ExpandedSubBlockEnd.gif            
#endregion
        
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理换行#region 处理换行
InBlock.gif            
//处理换行,在每个新行的前面添加两个全角空格
InBlock.gif
            r = new Regex(@"(\r\n((&nbsp;)| )+)(?<正文>\S+)",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),"<BR>  " + m.Groups["正文"].ToString());
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//处理换行,在每个新行的前面添加两个全角空格
InBlock.gif
            detail = detail.Replace("\r\n","<BR>");
InBlock.gif
InBlock.gif            
//unknown
InBlock.gif
//            sDetail = sDetail.Replace("\r\n","<BR><BR>"); 
InBlock.gif
//            sDetail = sDetail.Replace("\n","<BR>"); 
ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[b][/b]标记#region 处理[b][/b]标记
InBlock.gif            
//方法1
InBlock.gif
            r = new Regex(@"(\[b\])([ \S\t]*?)(\[\/b\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),"<B>" + m.Groups[2].ToString() + "</B>");
ExpandedSubBlockEnd.gif            }
        
InBlock.gif            
//方法2
InBlock.gif
//            detail = Regex.Replace(detail,@"\[b\](?<x>[^\]]*)\[/b\]",@"<b>$1</b>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif        
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[i][/i]标记#region 处理[i][/i]标记
InBlock.gif            
//方法1
InBlock.gif
            r = new Regex(@"(\[i\])([ \S\t]*?)(\[\/i\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),"<I>" + m.Groups[2].ToString() + "</I>");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//方法2            
InBlock.gif
//            detail = Regex.Replace(detail,@"\[i\](?<x>[^\]]*)\[/i\]",@"<i>$1</i>",RegexOptions.IgnoreCase);             
ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif        
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[U][/U]标记#region 处理[U][/U]标记
InBlock.gif            
//方法1
InBlock.gif
            r = new Regex(@"(\[U\])([ \S\t]*?)(\[\/U\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),"<U>" + m.Groups[2].ToString() + "</U>");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//方法2        
InBlock.gif
//            detail = Regex.Replace(detail,@"\[u\](?<x>[^\]]*)\[/u\]",@"<u>$1</u>",RegexOptions.IgnoreCase);                         
ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif            
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[p][/p]标记#region 处理[p][/p]标记        
InBlock.gif            r 
= new Regex(@"((\r\n)*\[p\])(.*?)((\r\n)*\[\/p\])",RegexOptions.IgnoreCase|RegexOptions.Singleline);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),"<P class=\"pstyle\">" + m.Groups[3].ToString() + "</P>");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[div][/div]标记#region 处理[div][/div]标记
InBlock.gif            detail 
= Regex.Replace(detail,@"\[center\](.[^\[]*)\[\/center\]",@"<div align=center>$1</div>",RegexOptions.IgnoreCase);             
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[font=xxx][/font]标记#region 处理[font=xxx][/font]标记        
InBlock.gif            r 
= new Regex(@"(\[font=([\S]+)\])([ \S\t]*?)(\[\/font\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<FONT FACE=" + m.Groups[2].ToString() + ">" + 
InBlock.gif                    m.Groups[
3].ToString() + "</FONT>");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[size=xxx][/size]标记#region 处理[size=xxx][/size]标记        
InBlock.gif            r 
= new Regex(@"(\[size=([1-7])\])([ \S\t]*?)(\[\/size\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<FONT SIZE=" + m.Groups[2].ToString() + ">" + 
InBlock.gif                    m.Groups[
3].ToString() + "</FONT>");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[color=xxx][/color]标记#region 处理[color=xxx][/color]标记            
InBlock.gif            r 
= new Regex(@"(\[color=([\S]+)\])([ \S\t]*?)(\[\/color\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<FONT COLOR=" + m.Groups[2].ToString() + ">" + 
InBlock.gif                    m.Groups[
3].ToString() + "</FONT>");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[H=x][/H]标记#region 处理[H=x][/H]标记            
InBlock.gif            r 
= new Regex(@"(\[H=([1-6])\])([ \S\t]*?)(\[\/H\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<H" + m.Groups[2].ToString() + ">" + 
InBlock.gif                    m.Groups[
3].ToString() + "</H" + m.Groups[2].ToString() + ">");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[fly][/fly]标记#region 处理[fly][/fly]标记 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[fly\](.[^\[]*)\[\/fly\]",@"<marquee width=90% behavior=alternate scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[move][/move]标记#region 处理[move][/move]标记 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[move\](.[^\[]*)\[\/move\]",@"<marquee scrollamount=3>$1</marquee>",RegexOptions.IgnoreCase);             
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[GLOW][/GLOW]标记#region 处理[GLOW][/GLOW]标记 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/GLOW\]",@"<div style=""width:$1px;filter:glow(color=$2, strength=$3)"">$4</div>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[SHADOW][/SHADOW]标记#region 处理[SHADOW][/SHADOW]标记 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/SHADOW\]",@"<div style=""width:$1px;filter:shadow(color=$2, strength=$3)"">$4</div>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[sup][/sup]标记#region 处理[sup][/sup]标记            
InBlock.gif            r 
= new Regex(@"(\[sup\])([ \S\t]*?)(\[\/sup\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),"<SUP>" + m.Groups[2].ToString() + "</SUP>");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[sub][/sub]标记#region 处理[sub][/sub]标记            
InBlock.gif            r 
= new Regex(@"(\[sub\])([ \S\t]*?)(\[\/sub\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),"<SUB>" + m.Groups[2].ToString() + "</SUB>");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif        
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[IMG][/IMG]标记#region 处理[IMG][/IMG]标记
InBlock.gif            detail 
= Regex.Replace(detail,@"\[IMG\](?<x>[^\]]*)\[\/IMG\]",@"<IMG SRC=""$1"" border=0>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[picture][/picture]标记,处理图片链接#region 处理[picture][/picture]标记,处理图片链接            
InBlock.gif            r 
= new Regex("\\[picture\\](\\d+?)\\[\\/picture\\]",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<A href=\"ShowImage.aspx?Type=ALL&Action=forumImage&ImageID=" + m.Groups[1].ToString() +
InBlock.gif
                    "\" target=\"_blank\"><IMG border=0 Title=\"点击打开新窗口查看\" src=\"ShowImage.aspx?Action=forumImage&ImageID=" + m.Groups[1].ToString() +
InBlock.gif                    
"\"></A>");
ExpandedSubBlockEnd.gif
            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[flash][/flash]标记#region 处理[flash][/flash]标记
InBlock.gif            detail 
= Regex.Replace(detail,@"\[flash\](?<x>[^\]]*)\[\/flash\]",@"<a href=""$1"" TARGET=_blank><IMG SRC=bbs/skins/default/filetype/swf.gif border=0 alt=点击开新窗口欣赏该FLASH动画! height=16 width=16>[全屏欣赏]</a><br/><OBJECT align=middle codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=""$1""><PARAM NAME=quality VALUE=high><embed src=""$1"" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400>$1</embed></OBJECT>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[flash=x,y][/flash]标记,自定义大小#region 处理[flash=x,y][/flash]标记,自定义大小 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[flash=*([0-9]*),*([0-9]*)\](?<x>[^\]]*)\[\/flash\]",@"<a href=""$3"" TARGET=_blank><IMG SRC=bbs/skins/default/filetype/swf.gif border=0 alt=点击开新窗口欣赏该FLASH动画! height=16 width=16>[全屏欣赏]</a><br/><OBJECT align=middle  codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=$1 height=$2><PARAM NAME=movie VALUE=""$3""><PARAM NAME=quality VALUE=high><embed src=""$3"" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=$1 height=$2>$3</embed></OBJECT>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[sound][/sound]标记#region 处理[sound][/sound]标记
InBlock.gif            detail 
= Regex.Replace(detail,@"\[sound\](.[^\[]*)\[\/sound\]",@"<a href=""$1"" target=_blank><IMG SRC=bbs/skins/default/filetype/mid.gif border=0 alt=""背景音乐""></a><bgsound src=""$1"" loop=""-1"">",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[mp=x,y][/mp]标记            Dv7 MediaPlayer自定义手动播放模式;#region 处理[mp=x,y][/mp]标记        Dv7 MediaPlayer自定义手动播放模式; 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[mp=*([0-9]*),*([0-9]*)\](?<x>[^\]]*)\[\/mp\]",@"<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$1 height=$2 ><param name=ShowStatusBar value=-1><param name=Filename value=$3><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$4 width=$1 height=$2></embed></object>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[mp=x,y,z][/mp]标记            Dv7 MediaPlayer自定义自动播放模式;#region 处理[mp=x,y,z][/mp]标记        Dv7 MediaPlayer自定义自动播放模式; 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[mp=*([0-9]*),*([0-9]*),*([0|1|true|false]*)\](?<x>[^\]]*)\[\/mp\]",@"<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$1 height=$2 ><PARAM NAME=AUTOSTART VALUE=$3 ><param name=ShowStatusBar value=-1><param name=Filename value=$4><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$4 width=$1 height=$2></embed></object>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[rm=x,y][/rm]标记            realplay视频文件#region 处理[rm=x,y][/rm]标记        realplay视频文件 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[rm=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/rm\]",@"<OBJECT align=middle  classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$1 height=$2><PARAM NAME=SRC VALUE=$3><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br/><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=$1><PARAM NAME=SRC VALUE=$3><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[rm=x,y,z][/rm]标记            realplay视频文件#region 处理[rm=x,y,z][/rm]标记        realplay视频文件 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[rm=*([0-9]*),*([0-9]*),*([0|1|true|false]*)\](.[^\[]*)\[\/rm\]",@"<OBJECT align=middle  classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$1 height=$2><PARAM NAME=SRC VALUE=$4><PARAM NAME=CONSOLE VALUE=""Clip""><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=$3 ></OBJECT><br/><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=$1><PARAM NAME=SRC VALUE=$4><PARAM NAME=AUTOSTART VALUE=$3><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=""Clip""></OBJECT>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[QT=x,y][/QT]标记            QuickTime视频文件#region 处理[QT=x,y][/QT]标记        QuickTime视频文件 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[QT=*([0-9]*),*([0-9]*)\](?<x>[^\]]*)\[\/QT\]",@"<embed src=$3 width=$1 height=$2 autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif                        
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[list=xxx][/list]标记#region 处理[list=xxx][/list]标记            
InBlock.gif            r 
= new Regex(@"(\[list(=(A|a|I|i| ))?\]([ \S\t]*)\r\n)((\[\*\]([ \S\t]*\r\n))*?)(\[\/list\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
string strLI = m.Groups[5].ToString();
InBlock.gif                Regex rLI 
= new Regex(@"\[\*\]([ \S\t]*\r\n?)",RegexOptions.IgnoreCase);
InBlock.gif                Match mLI;
InBlock.gif                
for (mLI = rLI.Match(strLI); mLI.Success; mLI = mLI.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    strLI 
= strLI.Replace(mLI.Groups[0].ToString(),"<LI>" + mLI.Groups[1]);
ExpandedSubBlockEnd.gif                }

InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<UL TYPE=\"" + m.Groups[3].ToString() + "\"><B>" + m.Groups[4].ToString() + "</B>" + 
InBlock.gif                    strLI 
+ "</UL>");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//unknown
InBlock.gif
//            detail = Regex.Replace(detail,@"\[list\](?<x>[^\]]*)\[/list\]",@"<ul>$1</ul>",RegexOptions.IgnoreCase); 
InBlock.gif
//            detail = Regex.Replace(detail,@"\[list=1\](?<x>[^\]]*)\[/list\]",@"<ol type=1>$1</ol id=1>",RegexOptions.IgnoreCase);         
InBlock.gif
//            detail = Regex.Replace(detail,@"\[list=a\](?<x>[^\]]*)\[/list\]",@"<ol type=a>$1</ol id=a>",RegexOptions.IgnoreCase);             
InBlock.gif
//            detail = Regex.Replace(detail,@"\[\*\](?<x>[^\]]*)\[/\*\]",@"<li>$1</li>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif
            #endregion
            
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[center][/center]标记#region 处理[center][/center]标记 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[center\](?<x>[^\]]*)\[\/center\]",@"<div align=center>$1</div>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[align=xxx][/align]标记#region 处理[align=xxx][/align]标记
InBlock.gif            r 
= new Regex(@"(\[align=([\S]+)\])([ \S\t]*?)(\[\/align\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<P align=" + m.Groups[2].ToString() + ">" + 
InBlock.gif                    m.Groups[
3].ToString() + "</P>");
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[url][/url]标记#region 处理[url][/url]标记        
InBlock.gif            
//方法1
InBlock.gif
            r = new Regex(@"(\[url\])([ \S\t]*?)(\[\/url\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<A href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/url.gif\">" +
InBlock.gif                    m.Groups[
2].ToString() + "</A>");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//方法2 
InBlock.gif
//            detail = Regex.Replace(detail,@"\[URL\](?<x>[^\]]*)\[\/URL\]",@"<a href=$1 target=_blank>$1</a>",RegexOptions.IgnoreCase);             
ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[url=xxx][/url]标记#region 处理[url=xxx][/url]标记
InBlock.gif            
//方法1
InBlock.gif
            r = new Regex(@"(\[url=([ \S\t]+)\])([ \S\t]*?)(\[\/url\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<A href=\"" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/url.gif\">" +
InBlock.gif                    m.Groups[
3].ToString() + "</A>");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//方法2 
InBlock.gif
//            detail = Regex.Replace(detail,@"\[URL=(?<x>[^\]]*)\](?<y>[^\]]*)\[\/URL\]",@"<a href=$1 target=_blank>$2</a>",RegexOptions.IgnoreCase);             
ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[email][/email]标记#region 处理[email][/email]标记    
InBlock.gif            
//方法1
InBlock.gif
            r = new Regex(@"(\[email\])([ \S\t]*?)(\[\/email\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +
InBlock.gif                    m.Groups[
2].ToString() + "</A>");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//方法2  
InBlock.gif
//            detail = Regex.Replace(detail,@"\[EMAIL\](?<x>[^\]]*)\[\/EMAIL\]",@"<img align=middle src=bbs/skins/default/email1.gif><A HREF=""mailto:$1"">$1</A>",RegexOptions.IgnoreCase);             
ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[email=xxx][/email]标记#region 处理[email=xxx][/email]标记
InBlock.gif            
//方法1
InBlock.gif
            r = new Regex(@"(\[email=([ \S\t]+)\])([ \S\t]*?)(\[\/email\])",RegexOptions.IgnoreCase);
InBlock.gif            
for (m = r.Match(detail); m.Success; m = m.NextMatch()) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                detail 
= detail.Replace(m.Groups[0].ToString(),
InBlock.gif                    
"<A href=\"mailto:" + m.Groups[2].ToString() + "\" target=\"_blank\"><IMG border=0 src=\"images/email.gif\">" +
InBlock.gif                    m.Groups[
3].ToString() + "</A>");
ExpandedSubBlockEnd.gif            }

InBlock.gif            
//方法2
InBlock.gif
//            detail = Regex.Replace(detail,@"\[EMAIL=(\S+\@.[^\[]*)\](?<y>[^\]]*)\[\/EMAIL\]",@"<img align=middle src=bbs/skins/default/email1.gif><A HREF=""mailto:$1"" TARGET=_blank>$2</A>",RegexOptions.IgnoreCase);             
ExpandedSubBlockEnd.gif
            #endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[quote][/quote]标记#region 处理[quote][/quote]标记
InBlock.gif            detail 
= Regex.Replace(detail,@"\[quote](?<x>.*)\[/quote]",@"<center>—— 以下是引用 ——<table border='1' width='80%' cellpadding='10' cellspacing='0'><tr><td>$1</td></tr></table></center>",RegexOptions.IgnoreCase);             
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[code][/code]标记#region 处理[code][/code]标记
InBlock.gif            detail 
= Regex.Replace(detail,@"\[code\](?<x>[^\]]*)\[/code\]",@"<table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""6""><td><b>以下内容为程序代码:</b><br/>$1</td></table>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[HTML][/HTML]标记#region 处理[HTML][/HTML]标记
InBlock.gif            detail 
= Regex.Replace(detail,@"\[HTML\](?<x>[^\]]*)\[\/HTML\]",@"table width=""100%"" border=""0"" cellspacing=""0"" cellpadding=""6""><td><b>以下内容为程序代码:</b><br/>$1</td></table>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif            
处理[DIR=x,y][/DIR]#region 处理[DIR=x,y][/DIR] 
InBlock.gif            detail 
= Regex.Replace(detail,@"\[DIR=*([0-9]*),*([0-9]*)\](?<x>[^\]]*)\[\/DIR\]",@"<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=$1 height=$2><param name=src value=$3><embed src=$3 pluginspage=http://www.macromedia.com/shockwave/download/ width=$1 height=$2></embed></object>",RegexOptions.IgnoreCase); 
ExpandedSubBlockEnd.gif            
#endregion

InBlock.gif            
InBlock.gif
InBlock.gif
InBlock.gif            
return detail;
InBlock.gif
//            return "<P Style=\"FONT-FAMILY: 宋体;LINE-HEIGHT: 13pt;word-wrap:break-word;\">" + sDetail + "</P>"; 
InBlock.gif

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

补:
ContractedBlock.gif ExpandedBlockStart.gif                  处理[upload]标记,处理上传图片 #region 处理[upload]标记,处理上传图片  
InBlock.gif                
string UpLoadPath="UpLoadPic/";        //路径可更改,图片名以upload_开头 
InBlock.gif
                detail = Regex.Replace(detail,@"\[upload_(.[^\[]*)\]",@"<img src="+UpLoadPath+"upload_$1 border=0 align=middle>",RegexOptions.IgnoreCase);  
ExpandedBlockEnd.gif                
#endregion
 
None.gif

其实是上传任何文件,如果只要传图片,则可以在程序中加以控制(如,控制后缀名)

改进:

ContractedBlock.gif ExpandedBlockStart.gif      处理[upload]标记,处理上传图片 #region 处理[upload]标记,处理上传图片   
InBlock.gif            
string UpLoadPath="UpLoadPic/";        //路径可更改,图片名以upload_开头              
InBlock.gif
            detail = Regex.Replace(detail,@"\[upload_(.[^\[]*)_(\d{1,2}|[1-2]\d{2}|3[0-1]\d|320)_([\d]+)\.(\w+)\]",@"<a href='" + UpLoadPath + "upload_$1_$2_$3.$4'><img src="+UpLoadPath+"upload_$1_$2_$3.$4 border=0 align=middle></a>",RegexOptions.IgnoreCase);   
InBlock.gif            detail 
= Regex.Replace(detail,@"\[upload_(.[^\[]*)_(3[2-9]\d|[4-9]\d{2}|\d{4,})_([\d]+)\.(\w+)\]",@"<a href='" + UpLoadPath + "upload_$1_$2_$3.$4'><img src="+UpLoadPath+"upload_$1_$2_$3.$4 border=0 align=middle width=320></a>",RegexOptions.IgnoreCase);   
ExpandedBlockEnd.gif            
#endregion
 

 

相关文件:

None.gif
None.gif        
private   void  ibtnUpLoad_Click( object  sender, System.Web.UI.ImageClickEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
if(upLoadFile.PostedFile.ContentLength > 524288)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Response.Write("<script>alert('图片请控制在500K以内!谢谢')</script>");
InBlock.gif                
return;
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            HttpPostedFile hpPFile 
= upLoadFile.PostedFile;    
InBlock.gif            
string localFile = hpPFile.FileName;
InBlock.gif
InBlock.gif            
//设置路径
InBlock.gif
            string strFolderName=Server.MapPath("UpLoadPic");
InBlock.gif            
//取得文件类型(后缀名)
ExpandedSubBlockStart.gifContractedSubBlock.gif
            char[] separator2 = dot.gif{'.'};        //separator的值为"\"
InBlock.gif
            string[] temp2  = localFile.Split(separator2);
InBlock.gif            
string strFileType  = temp2[temp2.Length-1];
InBlock.gif            
InBlock.gif            
//取得文件名(不含路径)
InBlock.gif
            char separator3 = '.';
InBlock.gif            
string strTemp  = localFile.Substring(0,localFile.LastIndexOf(separator3)-1);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
char[] separator = dot.gif{'\\'};        //separator的值为"\"
InBlock.gif
            string[] temp  = strTemp.Split(separator);
InBlock.gif            
string strFileName  = temp[temp.Length-1];            
InBlock.gif
InBlock.gif            System.IO.FileStream fs 
= new FileStream(localFile,FileMode.Open);
InBlock.gif            Bitmap bit 
= new Bitmap(fs);
InBlock.gif            
int picWidth = bit.Width;
InBlock.gif            
int picHeight = bit.Height;
InBlock.gif            fs.Close();
InBlock.gif
InBlock.gif            
string FileName = strFolderName + "\\upload_" + strFileName + "_" + picWidth + "_" + picHeight + "." + strFileType;
InBlock.gif                
InBlock.gif            
if(strFileType.ToLower() == "gif" || strFileType.ToLower() == "jpg")
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
try
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    hpPFile.SaveAs(FileName);            
InBlock.gif                    content.Value 
+= "[upload_" + strFileName + "_" + picWidth + "_" + picHeight + "." + strFileType + "]";                    
InBlock.gif                    
this.Response.Write("<script>alert('上传成功!')</script>");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
catch
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
this.Response.Write("<script>alert('上传失败!请重试!')</script>");
ExpandedSubBlockEnd.gif                }

InBlock.gif                
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.Response.Write("<script>alert('请选择有效的图片文件,目前只支持.gif和.jpg格式的图片!')</script>");
InBlock.gif                
ExpandedSubBlockEnd.gif            }

InBlock.gif                
ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/xiaodi/archive/2005/03/17/120475.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值