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

王朝other·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

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',

'%[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])](.*?)[/h1]%s',

'%[hr/]%s',

'%+)](.*?)%s',

'%+)](.*?)%s',

'%+)](.*?)%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="[url=mailto:1]mailto:1" 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;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航