中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > 综合其它
自己写的一个UBB转换的函数
作者:未知 时间:2005-09-13 23:35 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:自己写的一个UBB转换的函数
自己写的一个UBB转换的函数

function ubb2xhtml($ubb)
{
$flash=<<<END
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="%1$d" height="%2$d">
 <param name="movie" value="%3$s" />
 <param name="quality" value="high" />
 <embed src="%3$s" width="%1$d" height="%2$d" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
</object>
END;
 $match = array
 (
  '%\[url=([^\s]+)\](.*?)\[/url\]%s',
  '%\[email=([^\s])+\](.*?)\[/email\]%i',
  '%\[img width=(\d+) height=(\d+)\](.*?)\[/img\]%s',
  '%\[img=([^\s]+)\/\]%s',
  '%\[flash width=(\d+) height=(\d+)\](.*?)\[/flash\]%se',
  '%\[(b|i|u|strike|sup|sub)\](.*?)\[/\]%s',
  '%\[h([1-6])\](.*?)\[/h\]%s',
  '%\[hr\/\]%s',
  '%\[color=([^\s]+)\](.*?)\[/color\]%s',
  '%\[font=([^\"]+)\](.*?)\[/font\]%s',
  '%\[size=([^\s]+)\](.*?)\[/size\]%s',
  '%\[align=(center|right|left)\](.*?)\[/align\]%s',
  '%\[valign=(middle|top|bottom)\](.*?)\[/valign\]%s',
/*
  '%\[ul\](.*?)\[/ul\]%s',
  '%\[ul=(circle|disc|square)\](.*?)\[/ul\]%s',
  '%\[ol\](.*?)\[/ol\]%s',
  '%\[ol type=([aAiI1]) start=([a-zA-Z1-9])\](.*?)\[/ol\]%s',
  '%\[li\](.*?)\[/li\]%s',
*/
  '%\[table=([^\s]+?)\](.*?)\[/table\]%s',
  '%\[caption\](.*?)\[/caption\]%s',
  '%\[tr=([^\s]+?)\](.*?)\[/tr\]%s',
  '%\[th\](.*?)\[/th\]%s',
  '%\[td\](.*?)\[/td\]%s',
  '%\[note\](.*?)\[/note\]%s',
  '%\[quote=(.*?)\](.*?)\[/quote\]%s',
  '%\[code\](.*?)\[/code\]%s',
  '%[ ]%s',  // make double-spaces truly double-spaces!
 );
    $replace = array
 (
  '<a href="" target="_blank"></a>',
  '<a href="mailto:" target="_blank"></a>',
  '<img src="" width="" height="" border="0" />',
  '<img src="" border="0" />',
  'sprintf("$flash", "", "", "")',
  '<></>',
  '<h></h>',
  '<hr>\n',
  '<font color=""></font>',
  '<font face=""></font>',
  '<font size=""></font>',
  '<div align=""></font>',
  '<div valign=""></font>',
/*
  '<ul></ul>',
  '<ul type=""></ul>',
  '<ol></ol>',
  '<ol type="" start=""></ol>',
  '<li></li>',
*/
  "<table class=\"\" cellspacing=\"1\">\n</table>",
  "\t<caption></caption>\n",
  "\t<tr class=\"\">\n\t</tr>\n",
  "\t\t<th></th>\n",
  "\t\t<td></td>\n",
  '<div class="note"><span class="hint">发布者备注</span><hr /></div>',
  '<div class="quote"><span class="hint">引用</span>(来源: <a href="" target="_blank"></a>)<br /></div>',
  '<span class="hint" style="margin-left: 10px">代码</span><div class="code"></div>',
  '&nbsp; ',
 );
 if( preg_match('%\[table=(.*?)\/table\]%s', $ubb, $tablecells) ) //如果有表格, 先去除单元格之间的多余空白
 {
  $bb=preg_replace('%\]([\r\n\s]*)\[%si', '][', $tablecells[1]);
  $ubb=str_replace($tablecells[1], $bb, $ubb);
 }
 $html = preg_replace($match, $replace, nl2br(htmlspecialchars($ubb)));
 $html = preg_replace('/<br \/>\s*<(td|th|tr|table|ul|ol|li)/m', "\n".'<', $html);
 return $html;
}
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有