快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

自己写的一个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)](.*?)[/1]%s\\',
  \\'%[h([1-6])](.*?)[/h1]%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="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>\\',
  \\'<h1>2</h1>\\',
  \\'<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$2t</tr>n",
  "tt<th>$1</th>n",
  "tt<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(\\'%]([rns]*)[%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;
}
返回类别: 教程
上一教程: 桌面中央(一) 创建数据库   
下一教程: vBulletin HACK----关于排版的两个HACK

您可以阅读与"自己写的一个UBB转变的函数"相关的教程:
· 一个ubbcode的函数,速度很快.
· 一个阿拉伯数字转中文数字的函数
· 一个查看session内容的函数
· 一个取得文件扩展名的函数
· 自己写的mysql类
    微笑服务 优质保证 索取样品