• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

自己写的一个UBB转换的函数

发布: 2007-7-01 11:21 | 作者: admin | 来源: | 查看: 24次 | 进入软件测试论坛讨论

领测软件测试网 function ubb2xhtml($ubb)
{
$flash=<<<END
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
 codebase="" 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=">
</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)\](.*?)\[/\1\]%s@#,
  @#%\[h([1-6])\](.*?)\[/h\1\]%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@#,
  @#%[ ]{2}%s@#,  // make double-spaces truly double-spaces!
 );
    $replace = array
 (
  @#<a href="\1" target="_blank">\2</a>@#,
  @#<a href="" target="_blank">\2</a>@#,
  @#<img src="\3" width="\1" height="\2" border="0" />@#,
  @#<img src="\1" border="0" />@#,
  @#sprintf("$flash", "\1", "\2", "\3")@#,
  @#<\1>\2</\1>@#,
  @#<h\1>\2</h\1>@#,
  @#<hr>\n@#,
  @#<font color="\1">\2</font>@#,
  @#<font face="\1">\2</font>@#,
  @#<font size="\1">\2</font>@#,
  @#<div align="\1">\2</font>@#,
  @#<div valign="\1">\2</font>@#,
/*
  @#<ul>\1</ul>@#,
  @#<ul type="\1">\2</ul>@#,
  @#<ol>\1</ol>@#,
  @#<ol type="\1" start="\2">\3</ol>@#,
  @#<li>\1</li>@#,
*/
  "<table class=\"$1\" cellspacing=\"1\">\n$2</table>",
  "\t<caption>$1</caption>\n",
  "\t<tr class=\"$1\">\n$2\t</tr>\n",
  "\t\t<th>$1</th>\n",
  "\t\t<td>$1</td>\n",
  @#<div class="note"><span class="hint">发布者备注</span><hr />\1</div>@#,
  @#<div class="quote"><span class="hint">引用</span>(来源: <a href="\1" target="_blank">\1</a>)<br />\2</div>@#,
  @#<span class="hint" style="margin-left: 10px">代码</span><div class="code">\1</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".@#<\1@#, $html);
 return $html;
}

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网