| 自己写的一个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>', ' ', ); 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; }
|