位置: 东方标准 >> 教学中心 >> 专题讲座 >> 正文

UBB 转换函数演示

[ 作者:东方标准     来源:东方标准     文章录入:东方标准 ]
经典论坛的ubb转换我觉得是处理的非常好的,研究了一下它的转换结果[因为没有源码:)],做了下面的演示。转换结果基本上觉得象了。

    主要是针对[code]

以下内容为程序代码:
这两个标签的处理,其他的ubb标签还是一般的处理方法。

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

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

javascript:

运行代码框

<style>.codesamp {padding-right: 0.5em; margin-top: 1em; padding-left: 0.5em; font-size: 8p; margin-bottom: 1em; padding-bottom: 0.5em; margin-left: 0pt; padding-top: 0.5em; font-family: "courier new"; background-color: #eeeeee;width: 480px;overflow:hidden;border: 1px solid #888888;}textarea {border-width: 1; border-color: #000000;font-size: 12px;font-family: "tahoma", "ms shell dlg";}</style><textarea name=phx cols=65 rows=12>blue[html]test

以下内容为程序代码:
<b>以下内容为程序代码:</b><br>test
<b>以下内容为程序代码:</b><br><b>以下内容为程序代码:</b><br>test</textarea><br><button onclick=show.innerhtml=ubbcode(phx.value,"html")>转换</button><br><div id=show style="border:1 solid skyblue;width=500;font-size: 12px;font-family: 'tahoma', 'ms shell dlg';"></div><script>stricons = "1"  //允许笑脸转换strsmile="1"   //同上imgname="em"picurl="pic/"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\]([\s\s]+?)\[\/code\])/ig,"[/phx_code]$1[phx_code]");content=content.replace(/\[phx_code\]([\s\s]*?)\[\/phx_code\]/ig,function($1,$2){if(html=="html"){return(htmlcode($2));}else{return(trans($2));}});content=content.replace(/\[code\](\r\n)?([\s\s]+?)\[\/code\]/ig,function($1,$2,$3){return("<pre class=codesamp>"+dvbbshtmlan($3)+"</pre>")});content=content.replace(/\{(\/)?phx_code\}/ig,"[$1phx_code]");content=content.replace(/\{(\/)?phx_html\}/ig,"[$1phx_html]");alert('共耗时 '+eval(new date().gettime()-st)+' ms');return(content);}function htmlcode(content){content="[phx_html]"+content+"[/phx_html]";    content=content.replace(/(\[html\]([\s\s]+?)\[\/html\])/ig,"[/phx_html]$1[phx_html]");content=content.replace(/\[phx_html\]([\s\s]*?)\[\/phx_html\]/ig,function($1,$2){return(trans($2))});content=content.replace(/\[html\]([\s\s]+?)\[\/html\]/ig,function($1,$2){return("<span><textarea cols=95 rows=12>"+hencode($2)+"</textarea><br><input onclick=runcode() typ</div><div class='content_page' style='font-weight: bold;'><strong><font color='#ff0033'>[1]</font></strong> <a href='879620070120181406_P2.Html'>[2]</a> <a href='879620070120181406_P3.Html'>[3]</a> <a href='879620070120181406_P4.Html'>[4]</a> <a href='879620070120181406_P5.Html'>[5]</a> <a href='879620070120181406_P6.Html'>[6]</a> <a href='879620070120181406_P7.Html'>[7]</a> <a href='879620070120181406_P8.Html'>[8]</a> <a href='879620070120181406_P9.Html'>[9]</a> <a href='879620070120181406_P10.Html'>[10]</a> <a href='879620070120181406_P11.Html'>[11]</a>  <a href='879620070120181406_P2.Html'>下一页</a></div></div>
  <div class="con-maincontent"><ul><li> 上一篇文章:<a href='/i/xxyd/Class48/htmlcss/879520070120181401.Html' title='标题:用 onerror 获取错误信
作者:佚名
更新:2007-1-20 18:14:01
点击:562'>用 onerror 获取错误信</a></li>
    <li> 下一篇文章: <a href='/i/xxyd/Class48/htmlcss/879720070120181410.Html' title='标题:用js封装的时间设置器
作者:佚名
更新:2007-1-20 18:14:10
点击:564'>用js封装的时间设置器</a></li></ul></div>
  <div class="con-maincontent"> 
<a href="/Comment.asp?ChannelID=1011&Action=Write&InfoID=8796">发表评论</a> 
  
<a href="/User/SendMail.asp?Title=UBB 转换函数演示" target="_blank">告诉好友</a> 
  
<a href="javascript:window.print()">打印此文</a>
  
<a href="#" title="收藏的网页将被永久地保存到您的收藏夹中" onclick="window.open('/User/User_Favorite.Asp?title='+document.title+'&url='+document.location.href,'_blank', 'scrollbars=no,width=500,height=420,left=75,top=20,status=no,resizable=yes');">收藏此页</a>
  
<a href="javascript:window.close();">关闭窗口</a>
  
<a href="#">返回顶部</a></div>
</div>
</div>
</div>
<div class="con_gimpfoot">
</div><div class="foot-bg">
  <div class="foot-title"><a href="/Help.asp?Action=aboutweb">关于本站</a>Aboutweb | <a href="/LinkSite.asp">友情站点</a>LinkSite | <a href="/Help.asp?Action=contact">联系方式</a>Contact | <a href="/Help.asp?Action=remit">汇款方式</a>Remit | <a href="/Help.asp?Action=Copyright">版权申明</a>Copyright </div>
  <div class="foot-content">
<font color=#ffffff>
<br>地址:广州市北京路步行街312号青年文化宫6楼<br>
咨询电话:020-83303626 13288633114      咨询QQ群:11123656</font><br> Copyright© 1993-2007 <a href="http://www.gowinedu.com/">Gowinedu.com</a> .All Rights Reserved</div>
</div>
</body>
</html>     <!--在线咨询开始--><SCRIPT language=javascript src=/images/qqkf/tracqmove_ll.js></script>
<div id='tracqfloater' style='position:absolute; left:2px; top:88px;   width:104px; VISIBILITY: visible; height:170px; z-index:20'><table width='100%' border=0 cellspacing=0 cellpadding=0><table width=100 border=0 align=center cellpadding=0 cellspacing=0><tr><td><img src=/images/qqkf/up_new_001.gif  usemap=#m_about02 border=0 width=118 height=35></td></tr></table><div id='tracq1' style='z-index:20'><table width=100 border=0 align=top  cellpadding=0 cellspacing=0><tr><TD background=/images/qqkf/mid_new_001.gif  align=center valign=middle width=118 height=80>
<table border=0><tr><td height=20><a target=blank href=tencent://message/?uin=570307238&Site=www.onwww.cn&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:570307238:10 alt="点击这里给我发消息">许老师</a></td></tr><tr><td height=20><a target=blank href=tencent://message/?uin=787794778&Site=www.onwww.cn&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:787794778:10 alt="点击这里给我发消息">李老师</a></td></tr><tr><td height=20><a target=blank href=tencent://message/?uin=516573683&Site=www.onwww.cn&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:516573683:10 alt="点击这里给我发消息">贾老师</a></td></tr></table>
<map name=m_about02><area shape=rect coords='95, 6, 110, 20' ref=# onclick=javascript:hidenbox1(tracqfloater,tracq1) target=_blank alt='点击此处关闭洽谈通漂浮窗口!'></map><div id=sylapple style='position:absolute; left:5px; top:4px; z-index:20'>
<span class=tracqfloat_px12>在线客服</span></div></td></tr><tr><td><a href='#' title='控制面版管理中心' target=_self  onClick=javascript:window.open('http://www.gowinedu.com/Help.asp?Action=contact/'); 
return false; ><img src=/images/qqkf/bot_new_001.gif width=118  height=38
border=0 align=center></a></td></tr><tr><td><a href='#'  target=_self onClick=javascript:window.open('http://www.gowinedu.com/Help.asp?Action=contact/');  return false; >
<img src=/images/qqkf/down_new_001.gif width=118 height=24 border=0  lign=center></A></TD></TR></TBODY></TABLE>
<div style="visibility:hidden;top:160px;POSITION: absolute;">
<script src='http://s112.cnzz.com/stat.php?id=591073&web_id=591073' language='JavaScript' charset='gb2312'></script></div>
<!--在线咨询结束-->
<noscript><iframe src='*' width='0' height='0'></iframe></noscript>

<!--Powered by:CreateLive CMS Version 3.1(aspoo.net) CreateDate:2007-10-31 13:14:25-->

(只显示最新5条。评论内容只代表网友观点,与本站立场无关!) 发表评论