我是用Jscript写ASP程序的,动网的UBB转换不能用啊,谁有用JavaScript实现的UBB编码函数,能拿出来共享一下吗?谢谢:),高分送上啊,我一定很快结贴的!
---------------------------------------------------------------
function JsUBB(str)
{
var re=/\i\\[/i\]/gi;
str=str.replace(re,"
1<i>$1</i>
"); //斜体字
re=/\b\\[/b\]/gi;
str=str.replace(re,"
1<b>$1</b>
"); //粗体字
re=/\u\\[/u\]/gi;
str=str.replace(re,"
1<u>$1</u>
"); //下划线
re=/\[color=(.^\[]*)\\[/color\]/gi;
str=str.replace(re,"
1<font color="$1">$2</font>
"); //字体颜色
re=/\size=([1-7])\\[/size\]/gi;
str=str.replace(re,"
1<font size="$1">$2</font>
"); //字体大小
re=/\[face=(.^\[]*)\\[/face\]/gi;
str=str.replace(re,"
1<font face="$1">$2</font>
"); //字体
re=/\center\\[/center\]/gi;
str=str.replace(re,"
1<div align="center">$1</div>
"); //居中
re=/\right\\[/right\]/gi;
str=str.replace(re,"
1<div align="right">$1</div>
"); //右对齐
re=/\quote\\[/quote\]/gi; //引用
str=str.replace(re,"
1<table align="center" bgcolor="#E6FFE6" style="border:1px #009900 dotted" width="90%"><tr><td class="td1">$1</td></tr></table>
");
re=/\fly\\[/fly\]/gi; //飞行
str=str.replace(re,"
1<marquee behavior="alternate" scrollamount="3" width="90%">$1</marquee>
");
re=/\move\\[/move\]/gi; //移动
str=str.replace(re,"
1<marquee scrollamount="3">$1</marquee>
");
re=/\SHADOW=([0-9]),(#[a-z0-9]),([0-9]*)\\[/SHADOW]/gi; //阴影
str=str.replace(re,"
1<table width="$1"><tr><td style="filter:shadow(color=$2, strength=$3)">$4</td></tr></table>
");
re=/\GLOW=([0-9]),(#[a-z0-9]),([0-9]*)\\[/GLOW]/gi; //外发光
str=str.replace(re,"
1<table width="$1"><tr><td style="filter:glow(color=$2, strength=$3)">$4</td></tr></table>
")
re=/\URL\\[/URL\]/gi;
str=str.replace(re,"
1<a href="$1" target="_blank">$1</a>
"); //超链接1
re=/\[URL=(.^\[]*)\\[/URL\]/gi;
str=str.replace(re,"
1<a href="$1" target="_blank">$2</a>
"); //超链接2
re=/\EMAIL\\[/EMAIL\]/gi;
str=str.replace(re,"
1<a href="mailto:$1">$1</a>
"); //电子邮件链接1
re=/\EMAIL=([\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+)\\[/EMAIL\]/gi;
str=str.replace(re,"
1<a href="mailto:$1">$4</a>
"); //电子邮件链接2
re=/\img\\[/img\]/gi;
str=str.replace(re,"
1<a href="$1" target="_blank"><img alt="单击在新窗口浏览" border="0" src="$1"/></a>
"); //图片
re=/:em(\d{1,}):/gi;
str=str.replace(re,"
1<img border="0" src="emot/$1.gif"/>
"); //表情图标
return str;
}
//===================================
另外,“授人以鱼不如授人以渔”,呵呵,其实所有用VBS写的函数,Js都可以调用的,在服务器端。
假设有一个VBs的函数 VBUBBcode(str)
那么我们加上runat=Server,就可以用Js调用了:)
1<script language="VBScript" runat="Server">
2Function VBUBBcode(str)
3'...........
4End Function
5</script>