|
主题: 一个简单的UBB!
|
雅痞公子
职务:普通成员
等级:3
金币:-3.0
发贴:732
注册:2003/3/27 23:16:34
|
#12004/3/31 4:28:31
<cfscript> /** * ColdFusion MX Regular Expressions * * @author: Alex To (pknahws@hotmail.com) * @version: 1 * @lastModified: March 26,2004 */ function TextFormat(str){ var re=""; var content=str; content=Replace(content,"&","&","all"); content=Replace(content,"<","<","all"); content=Replace(content,">",">","all"); content=Replace(content,"#Chr(13)&Chr(10)#","<br>","all"); content=Replace(content,"#Chr(32)#"," ","all"); content=Replace(content,'"',""","all"); re="(\[url=((http):(\/\/|\\\\)?)?(.[^\[]*)\](.*?)\[\/url\])"; content=REReplaceNoCase(content,re,'<a href="http://\5" target="_blank" title="\5">\6</a>',"all"); re="(\[url\])((http):(\/\/|\\\\)?)?(.*?)(\[\/url\])"; content=REReplaceNoCase(content,re,'<a href="http://\5" target="_blank" title="\5">\5</a>',"all"); re="(\[mail=(.[^\[]*)\](.*?)\[\/mail\])"; content=REReplaceNoCase(content,re,'<a href="mailto:\2" title="\2">\3</a>',"all"); re="(\[mail\])(.*?)(\[\/mail\])"; content=REReplaceNoCase(content,re,'<a href="mailto:\2" title="\2">\2</a>',"all"); re="\[img\](.*?)\[\/img\]"; content=REReplaceNoCase(content,re,'<a href="\1" target="_blank" title="new Window"><img src="\1" border="0"></a>',"all"); re="\[flash\](.*?)\[\/flash\]"; content=REReplaceNoCase(content,re,'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=6,0,29,0" width="450" height="300"> <param name="movie" value="\1"> <param name="quality" value="high"> <embed src="\1" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="32" height="32"></embed></object>',"all");
re='([^(">)=])((http|https|ftp):(\/\/|\\\\)((\w)+[.]){1,}(com|net|cn|org|tv|[0-9]{1,3})(((\/|\\)(\w)+)|[.](\w)+)*(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)'; content=REReplaceNoCase(content,re,'\1<a href="\2" title="\2">\2</a>',"all"); re="(\[color=(.[^\[]*)\])(.*?)(\[\/color\])"; content=REReplaceNoCase(content,re,'<font color="\2">\3</font>',"all");
re="(\[size=(.[^\[]*)\])(.*?)(\[\/size\])"; content=REReplaceNoCase(content,re,'<font size="\2">\3</font>',"all"); content=REReplaceNoCase(content,"\[b\](.*?)\[\/b\]","<b>\1</b>","all"); content=REReplaceNoCase(content,"\[i\](.*?)\[\/i\]","<i>\1</i>","all"); content=REReplaceNoCase(content,"\[u\](.*?)\[\/u\]","<u>\1</u>","all"); content=REReplaceNoCase(content,"\[center\](.*?)\[\/center\]","<center>\1</center>","all"); content=REReplaceNoCase(content,"\[hr\]",'<hr size="1" noshade>',"all"); return content; } </cfscript>
|
吃鱼专家
职务:普通成员
等级:6
金币:11.0
发贴:5312
注册:2004/1/17 13:07:16
|
#22004/4/15 17:26:12
re="\[img\](.*?)\[\/img\]"; content=REReplaceNoCase(content,re,'<a href="\1" target="_blank" title="new Window"><img src="\1" border="0"></a>',"all" ; 这种看不明白,如果是要在修改时想把<img src="http://www.5d.cn/xxx.jpg">换成 应怎么写?
|
5DDC版主
职务:版主
等级:6
金币:10.0
发贴:3820
注册:2002/3/25 21:30:11
|
#32004/4/15 20:00:02
正则表示法
|
雅痞公子
职务:普通成员
等级:3
金币:-3.0
发贴:732
注册:2003/3/27 23:16:34
|
|
吃鱼专家
职务:普通成员
等级:6
金币:11.0
发贴:5312
注册:2004/1/17 13:07:16
|
#52004/4/25 20:16:51
怎么样才算热烈
|
雅痞公子
职务:普通成员
等级:3
金币:-3.0
发贴:732
注册:2003/3/27 23:16:34
|
#62004/5/22 23:27:41
<cfscript> /** * */ function HTMLFormat(text){ var content = text; content = Replace(content, Chr(38), '&', 'all'); content = Replace(content, Chr(60), '<', 'all'); content = Replace(content, Chr(62), '>', 'all'); content = Replace(content, Chr(34), '"', 'all'); content = Replace(content, Chr(32), ' ', 'all'); content = Replace(content, Chr(13)&Chr(10), '<br>', 'all'); return content; }
function rep(text,regular,substring){ return (REReplaceNoCase(text,regular,substring,'all')); }
function UBBFormat(text){ var tag = ''; var what = ''; var re = ''; var content = HTMLFormat(text); tag = StructNew(); tag.img = '<img src="\2\3" border="0">'; tag.w = '<iframe frameborder="1" align="center" scrolling="yes" src="\2\3" width="100%" height="400" marginheight="0" marginwidth="0"></iframe><br>页面:<a href="\2\3" target="_blank">点这儿参观</a>'; tag.f = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=6,0,29,0" width="500" height="300"><param name="movie" value="\2\3"><param name="quality" value="high"><embed src="\2\3" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="225"></embed></object>'; tag.url = '<a href="\2\3" target="_blank">\2\3</a>'; for(what in tag){ re = '(\[#what#\])(http|ftp|https)(\:\/\/.+?)(\[\/#what#\])'; content = rep(content,re,tag[what]); } tag = StructNew(); tag.url = '<a href="\2\3" target="_blank">\5</a>'; tag.download = '<img src="images/download.gif"><a href="\2\3">\5</a>'; for(what in tag){ re = '(\[#what#\=)(http|ftp|https)(\:\/\/.+?)(\])(.+?)(\[\/#what#\])'; content = rep(content,re,tag[what]); } tag = StructNew(); tag.b = '<b>\2</b>'; tag.i = '<i>\2</i>'; tag.u = '<u>\2</u>'; tag.sup = '<sup>\2</sup>'; tag.sub = '<sub>\2</sub>'; tag.list = '<ul>\2</ul>'; tag.code = '<div style="border:1px solid ##999999;"><pre>\2</pre></div>'; tag.center = '<div align="center">\2</div>'; tag.right = '<div align="right">\2</div>'; tag.url = '<a href="http://\2" target="_blank">\2</a>'; for(what in tag){ re = '(\[#what#\])(.+?)(\[\/#what#\])'; content = rep(content,re,tag[what]); } tag = StructNew(); tag.color = '<font color="\2">\4</font>'; tag.font = '<font face="\2">\4</font>'; tag.url = '<a href="http://\2" target="_blank">\4</a>'; for(what in tag){ re = '(\[#what#\=)(.+?)(\])(.+?)(\[\/#what#\])'; content = rep(content,re,tag[what]); } re = '(^| )(http|ftp|https)(:\/\/\w+([\.\~\-\/]\w+)+)'; content = rep(content, re, '\1<a href="\2\3" target="_blank">\2\3</a>'); re = '(^| )(www([\.\~\-\/]\w+)+)'; content = rep(content, re, '\1<a href="\2" target="_blank">\2</a>'); re = '(\[email\])([^\[]+?@[^\[]+?)(\[\/email\])'; content = rep(content, re, '<a href="mailto:\2">\2</a>'); re = '(\[email\=)(.+?@.+?)(\])(.+?)(\[\/email\])'; content = rep(content, re , '<a href="mailto:\2">\4</a>'); re = '(\[list=)(a|1|i)(\])(.+?)(\[\/list\])'; content = rep(content, re, '<ol type="\2">\4</ol>'); re = '(\[\*\])'; content = rep(content, re, '<li>'); re = '(\[h)([1-6])(\])(.+?)(\[\/h)(\2)(\])'; content = rep(content, re, '<h\2>\4</h\2>'); re = '(\[size=)([\+-]?[1-7])(\])(.+?)(\[\/size\])'; content = rep(content, re, '<font size="\2">\4</font>'); re = '(\[f w=)(\d{1,3})( h=)(\d{1,3})(\])(http|ftp|https)(\:\/\/.+?)(\[\/f\])'; content = rep(content, re, '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=6,0,29,0" width="\2" height="\4"><param name="movie" value="\6\7"><param name="quality" value="high"><embed src="\6\7" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="\2" height="\4"></embed></object>'); re = '(\[quote\])(.+?)(\[\/quote\])'; while(REFind(re, content) NEQ 0){ content = rep(content, re, '<blockquote>引用:<hr>\2<hr></blockquote>'); } return content; } </cfscript>
|
雅痞公子
职务:普通成员
等级:3
金币:-3.0
发贴:732
注册:2003/3/27 23:16:34
|
#72004/5/22 23:29:02
支持的 UBB 标记: [url] 链接地址[/url] [url= 链接地址] 说明文字[/url] [email] e-mail地址[/email] [email=e-mail地址]说明文字[/email] [download=下载文件地址]说明文字[/download] [img]图片地址[/img]
[code][/code] [ quote ]引用(可以嵌套)[ /quote ] [center][/center] [right][/right]
[b][/b] [u][/u] [i][/i] [sup][/sup] [sub][/sub] [ list ][ * ]text[ /list] [list=1 or A or I][ * ]text[/list] text [font=?][/font] [size=(+ or -)1-7][/size] [h1-6][/h1-6]
[w]网页地址[/w] [f]swf文件地址[/f] [f w=? h=?]
编辑历史:[此帖最近一次被 Alex-To 编辑过(编辑时间:2004-05-22 23:35:52)]
|