转换UBB代码得函数

 1public static string FormatUbb(string text)
 2        {    
 3            
 4            text=Regex.Replace(text,"\\[br\\]","<br/>",RegexOptions.IgnoreCase);
 5            /*title*/
 6            text=Regex.Replace(text,"\\[title\\](.*?)\\[/title\\]","<strong>$1</strong><br>",RegexOptions.IgnoreCase);
 7            /* image*/
 8            text=Regex.Replace(text,"\\[img\\](.*?)\\[/img\\]","<br/><a target='top' href=\"$1\"/><img border=0 alt='点击查看大图'  onload='if(this.width>600){this.width=600;this.height=this.height*this.width/600}' src=\"$1\"/></a><br/>",RegexOptions.IgnoreCase);
 9            text=Regex.Replace(text,"\\[img==*([0-9]*),*([0-9]*)\\](.*?)\\[/img\\]","<br/><a target='top' href=\"$3\"/><img border=0 alt='点击查看大图' width=$1 height=$2 src=\"$3\"/></a><br/>",RegexOptions.IgnoreCase);
10            /*mp3*/
11            text=Regex.Replace(text,"\\[mp3\\](.*?)\\[/mp3\\]","<br><object id=nstv classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 width=280 height=60 codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701standby=Loading Microsoft? Windows Media? Player components type=application/x-oleobject><param name=URL value=$1><PARAM NAME=UIMode value=full><PARAM NAME=AutoStart value=true><PARAM NAME=Enabled value=true><PARAM NAME=enableContextMenu value=false></object><br>",RegexOptions.IgnoreCase);
12            /* media*/
13            text=Regex.Replace(text,"\\*","*;",RegexOptions.IgnoreCase);
14            text=Regex.Replace(text,"\\[(\\/)?(MP(=([0-9]+),([0-9]+))?)\\]","*$1$2*",RegexOptions.IgnoreCase);
15            text=Regex.Replace(text,"\\*MP=([0-9]+),([0-9]+)\\*(.[^\\*]*\\.?(|avi|asx|wpl|aif|aifc|aiff|au|asf|mpeg|mpg|m1v|mp2|mpv2|mp2v|mpa|mid|midi|rmi|snd|wma|wmv|wm|wav|wax|w3u|wpl|mp3))\\*\\/MP\\*",
16                "<br><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=$3 width=$1 height=$2></embed></object><br>",RegexOptions.IgnoreCase);
17            text=Regex.Replace(text,"\\*(\\/)?(MP(=([0-9]+),([0-9]+))?)\\*","[$1$2]",RegexOptions.IgnoreCase);
18            text=Regex.Replace(text,"\\*;","*",RegexOptions.IgnoreCase);
19            /* relone*/
20            text=Regex.Replace(text,"\\*","*;",RegexOptions.IgnoreCase);
21            text=Regex.Replace(text,"\\[(\\/)?(RM(=([0-9]+),([0-9]+))?)\\]","*$1$2*",RegexOptions.IgnoreCase);
22            text=Regex.Replace(text,"\\*RM=([0-9]+),([0-9]+)\\*(.[^\\*]*\\.?(|rm|rma|ra|ram|rmm|rmvb|au|aif|mid|mp3|wav|wov|wma|smi|smil|m3u|mov|mpg|mpeg))\\*\\/RM\\*",
23                "<br><OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA height=$2 id=video1 width=$1 VIEWASTEXT><param name=_ExtentX value=5503><param name=_ExtentY value=1588><param name=AUTOSTART value=-1><param name=SHUFFLE value=0><param name=PREFETCH value=0><param name=NOLABELS value=0><param name=SRC value=$3><param name=CONTROLS value=Imagewindow,StatusBar,ControlPanel><param name=CONSOLE value=RAPLAYER><param name=LOOP value=0><param name=NUMLOOP value=0><param name=CENTER value=0><param name=MAINTAINASPECT value=0><param name=BACKGROUNDCOLOR value=#000000></OBJECT><br>",RegexOptions.IgnoreCase);
24            text=Regex.Replace(text,"\\*(\\/)?(RM(=([0-9]+),([0-9]+))?)\\*","[$1$2]",RegexOptions.IgnoreCase);
25            text=Regex.Replace(text,"\\*;","*",RegexOptions.IgnoreCase);
26            /* flash*/
27            text=Regex.Replace(text,"(\\[FLASH\\])(.*?)(\\[\\/FLASH\\])","<br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=400 height=300><PARAM NAME=movie VALUE=$2><PARAM NAME=quality VALUE=high><embed src=$2 quality=high pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=400 height=300>$2</embed></OBJECT><br>",RegexOptions.IgnoreCase);
28            text=Regex.Replace(text,"(\\[FLASH=*([0-9]*),*([0-9]*)\\])(.*?)(\\[\\/FLASH\\])","<a href=$4 TARGET=_blank><IMG SRC=http://www.newasp.net/Article/web/Dreamweaver/2005/pic/swf.gif border=0 alt=点击开新窗口欣赏该FLASH动画!> [全屏欣赏]</a><br><br><OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=$2 height=$3><PARAM NAME=movie VALUE=$4><PARAM NAME=quality VALUE=high><param name=menu value=false><embed src=$4 quality=high menu=false pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width=$2 height=$3>$4</embed></OBJECT>",RegexOptions.IgnoreCase);
29            /* url*/
30            text=Regex.Replace(text,"(\\[URL\\])(.*?)(\\[\\/URL\\])","<A HREF=$2 TARGET=_blank>$2</A>",RegexOptions.IgnoreCase);
31            text=Regex.Replace(text,"(\\[URL=(.[^\\[]*)\\])(.*?)(\\[\\/URL\\])","<A HREF=$2 TARGET=_blank>$3</A>",RegexOptions.IgnoreCase);
32            /* email*/
33            text=Regex.Replace(text,"(\\[EMAIL\\])(.*?)(\\[\\/EMAIL\\])","<A HREF=\"mailto:$2\">$2</A>",RegexOptions.IgnoreCase);
34            text=Regex.Replace(text,"(\\[EMAIL=(.[^\\[]*)\\])(.*?)(\\[\\/EMAIL\\])","<A HREF=\"mailto:$2\" TARGET=_blank>$3</A>",RegexOptions.IgnoreCase);
35            /* code */
36            text=Regex.Replace(text,"\\[code\\](<br \\/>|&nbsp;)*","<span style='position:relative;top:7px' class='bg1'>本帖相关代码如下</span><table width='95%' class='grid' cellpadding='0' cellspacing='0'><tr><td style='padding:10px 8px 8px 8px'>",RegexOptions.IgnoreCase);
37            text=Regex.Replace(text,"(<br \\/>|&nbsp;)*\\[\\/code\\]","</td></tr></table>",RegexOptions.IgnoreCase);
38            /* color*/
39            text=Regex.Replace(text,"(\\[color=(.[^\\[]*)\\])(.*?)(\\[\\/color\\])","<font color=$2>$3</font>",RegexOptions.IgnoreCase);
40            /* quote*/            
41            //text=Regex.Replace(text,"\\[quote user=\"(.*?)\"\\](.*?)\\[/quote\\]","<table title=\"引用\" width='95%' class='quote' cellpadding='0' cellspacing='0'><tr><td style='padding:10px 8px 8px 8px'>$1<td></tr><tr><td style='padding:10px 8px 8px 8px'>$2</td></tr></table><br>",RegexOptions.IgnoreCase);    
42        
43            text=Regex.Replace(text,"\\[quote user=''(.*?)''\\](<br \\/>|&nbsp;)*","<table  width='95%' class='quote' cellpadding='0' cellspacing='0' border='0'><caption align=\"left\">引用</caption><tr><td style='padding:10px 8px 8px 8px'><img src=\"/images/dreams/icon/icon-quote.gif\" border=\"0\" align=\"absmiddle\">    $1<td></tr><tr><td style='padding:10px 8px 8px 8px'>",RegexOptions.IgnoreCase);    
44            text=Regex.Replace(text,"\\[quote user=\"(.*?)\"\\](<br \\/>|&nbsp;)*","<table  width='95%' class='quote' cellpadding='0' cellspacing='0' border='0'><caption align=\"left\">引用</caption><tr><td style='padding:10px 8px 8px 8px'><img src=\"/images/dreams/icon/icon-quote.gif\" border=\"0\" align=\"absmiddle\">    $1<td></tr><tr><td style='padding:10px 8px 8px 8px'>",RegexOptions.IgnoreCase);    
45            text=Regex.Replace(text,"(<br \\/>|&nbsp;)*\\[/quote\\]","</td></tr></table><br>",RegexOptions.IgnoreCase);            
46            /* underline */
47            text=Regex.Replace(text,"(\\[i\\])(.*?)(\\[\\/i\\])","<i>$2</i>",RegexOptions.IgnoreCase);
48            /* itatic */
49            text=Regex.Replace(text,"(\\[u\\])(.*?)(\\[\\/u\\])","<u>$2</u>",RegexOptions.IgnoreCase);
50            /* bold */
51            text=Regex.Replace(text,"(\\[b\\])(.*?)(\\[\\/b\\])","<b>$2</b>",RegexOptions.IgnoreCase);
52            /* line */
53            text=Regex.Replace(text,"\\[line\\/\\]","<hr size='1' noshade='noshade' />",RegexOptions.IgnoreCase);
54            text=Regex.Replace(text,"\\[line\\]\\s*(\\d{1})\\s*,\\s*((#[A-Fa-f0-9]{3})|(#[A-Fa-f0-9]{6})|[A-Za-z]{3,12})\\s*\\[\\/line\\]","<hr size='$1' style='border:1px $2 solid' color='$2' noshade='noshade' />",RegexOptions.IgnoreCase);
55            /* font size */
56            text=Regex.Replace(text,"(\\[size=1\\])(.*?)(\\[\\/size\\])","<font size=1>$2</font>",RegexOptions.IgnoreCase);
57            text=Regex.Replace(text,"(\\[size=2\\])(.*?)(\\[\\/size\\])","<font size=2>$2</font>",RegexOptions.IgnoreCase);
58            text=Regex.Replace(text,"(\\[size=3\\])(.*?)(\\[\\/size\\])","<font size=3>$2</font>",RegexOptions.IgnoreCase);
59            text=Regex.Replace(text,"(\\[size=4\\])(.*?)(\\[\\/size\\])","<font size=4>$2</font>",RegexOptions.IgnoreCase);
60            text=Regex.Replace(text,"(\\[size=5\\])(.*?)(\\[\\/size\\])","<font size=5>$2</font>",RegexOptions.IgnoreCase);
61            text=Regex.Replace(text,"(\\[size=6\\])(.*?)(\\[\\/size\\])","<font size=6>$2</font>",RegexOptions.IgnoreCase);
62            text=Regex.Replace(text,"\\[size=([+|-]?[0-7])\\](.*?)(\\[\\/size\\])","<font size=$1>$2</font>",RegexOptions.IgnoreCase);
63            /* center */
64            text=Regex.Replace(text,"(\\[center\\])(.*?)(\\[\\/center\\])","<center>$2</center>",RegexOptions.IgnoreCase);
65            /* left */
66            text=Regex.Replace(text,"(\\[left\\])(.*?)(\\[\\/left\\])","<p align=left>$2</p>",RegexOptions.IgnoreCase);
67            /* right */
68            text=Regex.Replace(text,"(\\[right\\])(.*?)(\\[\\/right\\])","<p align=right>$2</p>",RegexOptions.IgnoreCase);
69            text=Regex.Replace(text,"(\\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\\])(.*?)(\\[\\/GLOW\\])","<div style='width:$2;filter:glow(color=$3,strength=$4)'>$5</div>",RegexOptions.IgnoreCase);
70            text=Regex.Replace(text,"(\\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\\])(.*?)(\\[\\/SHADOW\\])","<div style='width:$2;filter:shadow(color=$3,strength=$4)'>$5</div>",RegexOptions.IgnoreCase);
71            /* fly */
72            text=Regex.Replace(text,"(\\[fly\\])(.*?)(\\[/fly\\])","<marquee behavior='scroll'speed='1' onmouseover='stop()' onmouseout='start()'>$2</marquee>",RegexOptions.IgnoreCase);
73            /* move*/
74            text=Regex.Replace(text,"(\\[move\\])(.*?)(\\[/move\\])","<marquee scrollamount=3>$2</marquee>",RegexOptions.IgnoreCase);
75            /* face*/
76            text=Regex.Replace(text,"(\\[face=(.*?)])(.*?)(\\[/face\\])","<FONT face=$2>$3</FONT>",RegexOptions.IgnoreCase);
77            /* bgsound*/
78            text=Regex.Replace(text,"(\\[sound\\])(.*?)(\\[/sound\\])","<bgsound src=$2 loop=3>",RegexOptions.IgnoreCase);
79            return text;
80        }
posted @ 2006-04-12 12:41  Robin Zhang  阅读(685)  评论(1编辑  收藏  举报