1 <?php
2
3 function ubb2xhtml($ubb)
4 {
5 $flash=<<<END
6 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
7 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="%1/$d" height="%2/$d">
8 <param name="movie" value="%3/$s" />
9 <param name="quality" value="high" />
10 <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>
11 </object>
12 END;
13 $match = array
14 (
15 '%/[url=([^/s]+)/](.*?)/[/url/]%s',
16 '%/[email=([^/s])+/](.*?)/[/email/]%i',
17 '%/[img width=(/d+) height=(/d+)/](.*?)/[/img/]%s',
18 '%/[img=([^/s]+)///]%s',
19 '%/[flash width=(/d+) height=(/d+)/](.*?)/[/flash/]%se',
20 '%/[(b|i|u|strike|sup|sub)/](.*?)/[//1/]%s',
21 '%/[h([1-6])/](.*?)/[/h/1/]%s',
22 '%/[hr///]%s',
23 '%/[color=([^/s]+)/](.*?)/[/color/]%s',
24 '%/[font=([^/"]+)/](.*?)/[/font/]%s',
25 '%/[size=([^/s]+)/](.*?)/[/size/]%s',
26 '%/[align=(center|right|left)/](.*?)/[/align/]%s',
27 '%/[valign=(middle|top|bottom)/](.*?)/[/valign/]%s',
28 /*
29 '%/[ul/](.*?)/[/ul/]%s',
30 '%/[ul=(circle|disc|square)/](.*?)/[/ul/]%s',
31 '%/[ol/](.*?)/[/ol/]%s',
32 '%/[ol type=([aAiI1]) start=([a-zA-Z1-9])/](.*?)/[/ol/]%s',
33 '%/[li/](.*?)/[/li/]%s',
34 */
35 '%/[table=([^/s]+?)/](.*?)/[/table/]%s',
36 '%/[caption/](.*?)/[/caption/]%s',
37 '%/[tr=([^/s]+?)/](.*?)/[/tr/]%s',
38 '%/[th/](.*?)/[/th/]%s',
39 '%/[td/](.*?)/[/td/]%s',
40 '%/[note/](.*?)/[/note/]%s',
41 '%/[quote=(.*?)/](.*?)/[/quote/]%s',
42 '%/[code/](.*?)/[/code/]%s',
43 '%[ ]{2}%s', // make double-spaces truly double-spaces!
44 );
45
46 $replace = array
47 (
48 '<a href="/1" _fcksavedurl=""/1"" _fcksavedurl=""/1"" _fcksavedurl=""/1"" target="_blank">/2</a>',
49 '<a href="mailto:/1" target="_blank">/2</a>',
50 '<img src="/3" width="/1" height="/2" border="0" />',
51 '<img src="/1" border="0" />',
52 'sprintf("$flash", "/1", "/2", "/3")',
53 '</1>/2<//1>',
54 '<h/1>/2</h/1>',
55 '<hr>/n',
56 '<font color="/1">/2</font>',
57 '<font face="/1">/2</font>',
58 '<font size="/1">/2</font>',
59 '<div align="/1">/2</font>',
60 '<div valign="/1">/2</font>',
61 /*
62 '<ul>/1</ul>',
63 '<ul type="/1">/2</ul>',
64 '<ol>/1</ol>',
65 '<ol type="/1" start="/2">/3</ol>',
66 '<li>/1</li>',
67 */
68 "<table class=/"$1/" cellspacing=/"1/">/n$2</table>",
69 "/t<caption>$1</caption>/n",
70 "/t<tr class=/"$1/">/n$2/t</tr>/n",
71 "/t/t<th>$1</th>/n",
72 "/t/t<td>$1</td>/n",
73 '<div class="note"><span class="hint">NOTE</span><hr />/1</div>',
74 '<div class="quote"><span class="hint">QUOTE</span>(from: <a href="/1" target="_blank">/1</a>)<br />/2</div>',
75 '<span class="hint" style="margin-left: 10px">CODE</span><div class="code">/1</div>',
76 ' ',
77 );
78
79 if( preg_match('%/[table=(.*?)//table/]%s', $ubb, $tablecells) ) // remove spaces between tables in any
80 {
81 $bb=preg_replace('%/]([/r/n/s]*)/[%si', '][', $tablecells[1]);
82 $ubb=str_replace($tablecells[1], $bb, $ubb);
83 }
84 $html = preg_replace($match, $replace, nl2br(htmlspecialchars($ubb)));
85 $html = preg_replace('/<br //>/s*<(td|th|tr|table|ul|ol|li)/m', "/n".'</1', $html);
86 return $html;
87 }
88 ?>
自己写的一个UBB转换的函数
最新推荐文章于 2021-03-11 06:17:29 发布