UBB 转换函数演示

作者:袖梨 2022-07-02

  UBB代码对于经常上论坛的朋友来说是最熟悉不过了。
经典论坛的UBB转换我觉得是处理的非常好的,研究了一下它的转换结果[因为没有源码:)],做了下面的演示。转换结果基本上觉得象了。

    主要是针对[code][html]这两个标签的处理,其他的UBB标签还是一般的处理方法。

    下面是分别用javascript和vbscript实现的演示。自己做论坛的朋友,如果想实现类似经典论坛的运行代码框可以看看这种转换。

欢迎大家输入尽量多格式的UBB进行测试,多多指出错误。

javascript:


[i][b][color=blue]blue[/color][/b][/i]

[html][color=red]te
st[/color][/html]

[html][code]te
st[/code][/html]

[code][html]te
st[/html][/code]

转换


function UBBCode(content,html){
st=new Date().getTime()
content=content.replace(/[(/)?phx_code]/ig,"{$1phx_code}");
content=content.replace(/[(/)?phx_html]/ig,"{$1phx_html}");
content="[phx_code]"+content+"[/phx_code]";         
content=content.replace(/([code]([sS]+?)[/code])/ig,"[/phx_code]$1[phx_code]");
content=content.replace(/[phx_code]([sS]*?)[/phx_code]/ig,function($1,$2){if(html=="html"){return(HTMLCode($2));}else{return(trans($2));}});
content=content.replace(/[code](rn)?([sS]+?)[/code]/ig,function($1,$2,$3){return("

"+DvbbsHtmlAn($3)+"
")});
content=content.replace(/{(/)?phx_code}

相关文章

精彩推荐