ubbcode简单实用
<%
function chkbadwords(fstring)
if not(isnull(badwords) or isnull(fstring)) then
bwords = split(badwords, "|")
for i = 0 to ubound(bwords)
fstring = replace(fstring, bwords(i), string(len(bwords(i)),"*"))
next
chkbadwords = fstring
end if
end function
function htmlencode(fstring)
if not isnull(fstring) then
'fstring = replace(fstring, chr(38), "&")
'fstring = replace(fstring, ">", ">")
'fstring = replace(fstring, "<", "<")
'fstring = replace(fstring, chr(39), "'")
'fstring = replace(fstring, chr(32), " ")
'fstring = replace(fstring, chr(34), """)
'fstring = replace(fstring, chr(13), "")
fstring = replace(fstring, chr(10), "<br/>")
htmlencode = fstring
end if
end function
function htmlcode(fstring)
if not isnull(fstring) then
fstring = replace(fstring, chr(13), "")
fstring = replace(fstring, chr(10), "<br/>")
htmlcode = fstring
end if
end function
function htmldecode(fstring)
if not isnull(fstring) then
'fstring = replace(fstring, chr(38), "&")
'fstring = replace(fstring, ">", ">")
'fstring = replace(fstring, "<", "<")
'fstring = replace(fstring, chr(32), " ")
'fstring = replace(fstring,"",chr(13))
fstring = replace(fstring,"<br/>",chr(10))
htmldecode = fstring
end if
end function
function ubbcode(strcontent)
if strallowhtml <> 1 then
strcontent = htmlencode(strcontent)
else
strcontent = htmlcode(strcontent)
end if
dim re
set re=new regexp
re.ignorecase =true
re.global=true
re.pattern="\[img\](.[^\[]*)\[\/img\]"
strcontent=re.replace(strcontent,"<img src=""$1"" border=""0""></img>")
re.pattern="\[img=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/img\]"
strcontent=re.replace(strcontent,"<a href=""$3"" title=点击看全图 target=_blank><img src=""$3"" width=""$1"" height=""$2"" border=""0""></img></a>")
'图文混排
re.pattern="\[pic\](.[^\[]*)\[\/pic\]"
strcontent=re.replace(strcontent,"<img src=""$1"" border=""0"" align=""left""></img>")
re.pattern="\[pic=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/pic\]"
strcontent=re.replace(strcontent,"<a href=""$3"" title=点击看全图 target=_blank><img src=""$3"" width=""$1"" height=""$2"" border=""0"" align=""left""></img></a>")
re.pattern="\[flash=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/flash\]"
strcontent= re.replace(strcontent,"<embed src=""$3"" width=""$1"" height=""$2""></embed>")
re.pattern="\[flash\](.[^\[]*)\[\/flash\]"
strcontent= re.replace(strcontent,"<embed src=""$1""></embed>")
re.pattern="(\[url\])(http:\/\/.[^\[]*)(\[\/url\])"
strcontent= re.replace(strcontent,"<a href=""$2"" target=""_blank"">$2</a>")
re.pattern="(\[url\])(.[^\[]*)(\[\/url\])"
strcontent= re.replace(strcontent,"<a href=""http://$2"" target=""_blank"">$2</a>")
re.pattern="(\[email\])(mailto:\/\/.[^\[]*)(\[\/email\])"
strcontent= re.replace(strcontent,"<a href=""$2"" target=""_blank"">$2</a>")
re.pattern="(\[email\])(.[^\[]*)(\[\/email\])"
strcontent= re.replace(strcontent,"<a href=""mailto:$2"" target=""_blank"">$2</a>")
re.pattern="(\[url=(http:\/\/.[^\[]*)\])(.[^\[]*)(\[\/url\])"
strcontent= re.replace(strcontent,"<a href=""$2"" target=""_blank"">$3</a>")
re.pattern="(\[url=(.[^\[]*)\])(.[^\[]*)(\[\/url\])"
strcontent= re.replace(strcontent,"<a href=""http://$2"" target=""_blank"">$3</a>")
re.pattern = "^(http://[a-za-z0-9\./=\?%\-&_~`@':+!]+)"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "(http://[a-za-z0-9\./=\?%\-&_~`@':+!]+)$"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "[^>=""](http://[a-za-z0-9\./=\?%\-&_~`@':+!]+)"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "^(ftp://[a-za-z0-9\./=\?%\-&_~`@':+!]+)"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "(ftp://[a-za-z0-9\./=\?%\-&_~`@':+!]+)$"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "[^>=""](ftp://[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "^(rtsp://[a-za-z0-9\./=\?%\-&_~`@':+!]+)"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "(rtsp://[a-za-z0-9\./=\?%\-&_~`@':+!]+)$"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "[^>=""](rtsp://[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "^(mms://[a-za-z0-9\./=\?%\-&_~`@':+!]+)"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "(mms://[a-za-z0-9\./=\?%\-&_~`@':+!]+)$"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern = "[^>=""](mms://[a-za-z0-9\.\/=\?%\-&_~`@':+!]+)"
strcontent = re.replace(strcontent,"<img align=absmiddle src=http://www.ceocio.net/images/url.gif><a target=_blank href=$1>$1</a>")
re.pattern="\[dir=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/dir]"
strcontent=re.replace(strcontent,"<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>")
re.pattern="\[qt=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/qt]"
strcontent=re.replace(strcontent,"<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/>")
re.pattern="\[mp=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/mp]"
strcontent=re.replace(strcontent,"<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>")
re.pattern="\[rm=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/rm]"
strcontent=re.replace(strcontent,"<object 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>")
re.pattern="(\[color=(.[^\[]*)\])(.[^\[]*)(\[\/color\])"
strcontent=re.replace(strcontent,"<font color=""$2"">$3</font>")
re.pattern="(\[face=(.[^\[]*)\])(.[^\[]*)(\[\/face\])"
strcontent=re.replace(strcontent,"<font face=""$2"">$3</font>")
re.pattern="(\[align=(.[^\[]*)\])(.*)(\[\/align\])"
strcontent=re.replace(strcontent,"<div align=""$2"">$3</div>")
re.pattern="(\[quote\])(.*)(\[\/quote\])"
strcontent=re.replace(strcontent,"<table cellpadding=""0"" cellspacing=""0"" border=""0"" width=""94%"" bgcolor=""#d7f0ff"" align=""center""><tr><td><table width=""100%"" cellpadding=""5"" cellspacing=""1"" border=""0""><tr><td bgcolor='"&abgcolor&"'>$2</table></table><br>")
re.pattern="(\[fly\])(.*)(\[\/fly\])"
strcontent=re.replace(strcontent,"<marquee width=""90%"" behavior=""alternate"" scrollamount=""3"">$2</marquee>")
re.pattern="(\[move\])(.*)(\[\/move\])"
strcontent=re.replace(strcontent,"<marquee scrollamount=""3"">$2</marquee>")
re.pattern="\[glow=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/glow]"
strcontent=re.replace(strcontent,"<table width=""$1"" style=""filter:glow(color=$2, strength=$3)"">$4</table>")
re.pattern="\[shadow=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/shadow]"
strcontent=re.replace(strcontent,"<table width=$1 style=""filter:shadow(color=$2, strength=$3)"">$4</table>")
re.pattern="(\[i\])(.[^\[]*)(\[\/i\])"
strcontent=re.replace(strcontent,"<i>$2</i>")
re.pattern="(\[u\])(.[^\[]*)(\[\/u\])"
strcontent=re.replace(strcontent,"<u>$2</u>")
re.pattern="(\[b\])(.[^\[]*)(\[\/b\])"
strcontent=re.replace(strcontent,"<b>$2</b>")
re.pattern="(\[fly\])(.[^\[]*)(\[\/fly\])"
strcontent=re.replace(strcontent,"<marquee>$2</marquee>")
re.pattern="(\[size=1\])(.[^\[]*)(\[\/size\])"
strcontent=re.replace(strcontent,"<font size=""1"">$2</font>")
re.pattern="(\[size=2\])(.[^\[]*)(\[\/size\])"
strcontent=re.replace(strcontent,"<font size=""2"">$2</font>")
re.pattern="(\[size=3\])(.[^\[]*)(\[\/size\])"
strcontent=re.replace(strcontent,"<font size=""3"">$2</font>")
re.pattern="(\[size=4\])(.[^\[]*)(\[\/size\])"
strcontent=re.replace(strcontent,"<font size=""4"">$2</font>")
re.pattern="(\[center\])(.[^\[]*)(\[\/center\])"
strcontent=re.replace(strcontent,"<center>$2</center>")
'以下扩展
re.pattern="(\[li\])(.[^\[]*)(\[\/li\])"
strcontent=re.replace(strcontent,"<li>$2</li>")
'字体背景
re.pattern="(\[fontbg=(.[^\[]*)\])(.[^\[]*)(\[\/fontbg\])"
strcontent=re.replace(strcontent,"<span style=background-color:""$2"">$3</span>")
'删除线
re.pattern="(\[strike\])(.[^\[]*)(\[\/strike\])"
strcontent=re.replace(strcontent,"<strike>$2</strike>")
re.pattern="(\[html\])(.[^\[]*)(\[\/html\])"
strcontent=re.replace(strcontent,"<table width='100%' border='0' cellspacing='0' cellpadding='6' bgcolor='"&abgcolor&"'><td><b>以下内容为程序代码:</b><br>$2</td></table>")
re.pattern="(\[code\])(.[^\[]*)(\[\/code\])"
strcontent=re.replace(strcontent,"<table width='100%' border='0' cellspacing='0' cellpadding='6' bgcolor='"&abgcolor&"'><td><b>以下内容为程序代码:</b><br>$2</td></table>")
strcontent=chkbadwords(strcontent)
set re=nothing
ubbcode=strcontent
end function
%>
上一篇: vue中实现滚动加载更多的示例
下一篇: 简单的Html转换UBB的程序