ubb|函数|转换
function ubb2xhtml($ubb)
{
$flash= codebase= width=%1\$d height=%2\$d>
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=([^\> @#%\[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
(
@#\2@#,
@#\2@#,
@#@#,
@#@#,
@#sprintf($flash, \1, \2, \3)@#,
@#\2\1>@#,
@#\2\1>@#,
@#
\n@#,
@#\2@#,
@#\2@#,
@#\2@#,
@#\2@#,
@#\2@#,
/*
@#\1@#,
@#\2@#,
@#\1@#,
@#\3@#,
@#\1@#,
*/
\n$2
,
\t$1\n,
\t\n$2\t
\n,
\t\t$1\n,
\t\t$1 \n,
@#发布者备注\1
@#,
@#引用(来源: \1)
\2
@#,
@#代码\1
@#,
@# @#,
);
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(@#/
\s* return $html;
}