php UBB 解析實(shí)現(xiàn)代碼
更新時(shí)間:2011年11月27日 00:26:08 作者:
今天看thinkphp演示文檔看到這個(gè)ubb的代碼感覺還可以。
復(fù)制代碼 代碼如下:
/**
+----------------------------------------------------------
* UBB 解析
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
function ubb($Text) {
$Text=trim($Text);
$Text=ereg_replace("\n","<br>",$Text);
$Text=preg_replace("/\\t/is"," ",$Text);
$Text=preg_replace("/\[hr\]/is","<hr>",$Text);
$Text=preg_replace("/\[separator\]/is","<br/>",$Text);
$Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","<h1>\\1</h1>",$Text);
$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
$Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","<h3>\\1</h3>",$Text);
$Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","<h4>\\1</h4>",$Text);
$Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","<h5>\\1</h5>",$Text);
$Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","<h6>\\1</h6>",$Text);
$Text=preg_replace("/\[center\](.+?)\[\/center\]/is","<center>\\1</center>",$Text);
//$Text=preg_replace("/\[url=([^\[]*)\](.+?)\[\/url\]/is","<a href=\\1 target='_blank'>\\2</a>",$Text);
$Text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"\\1\" target='_blank'>\\1</a>",$Text);
$Text=preg_replace("/\[url=(http:\/\/.+?)\](.+?)\[\/url\]/is","<a href='\\1' target='_blank'>\\2</a>",$Text);
$Text=preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/is","<a href=\\1>\\2</a>",$Text);
$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\\1>",$Text);
$Text=preg_replace("/\[img\s(.+?)\](.+?)\[\/img\]/is","<img \\1 src=\\2>",$Text);
$Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$Text);
$Text=preg_replace("/\[colorTxt\](.+?)\[\/colorTxt\]/eis","color_txt('\\1')",$Text);
$Text=preg_replace("/\[style=(.+?)\](.+?)\[\/style\]/is","<div class='\\1'>\\2</div>",$Text);
$Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","<font size=\\1>\\2</font>",$Text);
$Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","<sup>\\1</sup>",$Text);
$Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","<sub>\\1</sub>",$Text);
$Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","<pre>\\1</pre>",$Text);
$Text=preg_replace("/\[emot\](.+?)\[\/emot\]/eis","emot('\\1')",$Text);
$Text=preg_replace("/\[email\](.+?)\[\/email\]/is","<a href='mailto:\\1'>\\1</a>",$Text);
$Text=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$Text);
$Text=preg_replace("/\[u\](.+?)\[\/u\]/is","<u>\\1</u>",$Text);
$Text=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$Text);
$Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote>引用:<div style='border:1px solid silver;background:#EFFFDF;color:#393939;padding:5px' >\\1</div></blockquote>", $Text);
$Text=preg_replace("/\[code\](.+?)\[\/code\]/eis","highlight_code('\\1')", $Text);
$Text=preg_replace("/\[php\](.+?)\[\/php\]/eis","highlight_code('\\1')", $Text);
$Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<div style='text-align: left; color: darkgreen; margin-left: 5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>", $Text);
return $Text;
}
相關(guān)文章
PHP iconv()函數(shù)字符編碼轉(zhuǎn)換的問題講解
今天小編就為大家分享一篇關(guān)于PHP iconv()函數(shù)字符編碼轉(zhuǎn)換的問題講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03PHP gbk環(huán)境下json_dencode傳送來的漢字
在做一個(gè)小項(xiàng)目的時(shí)候用得gbk,發(fā)現(xiàn)json_encode傳過來的漢子不對(duì)。搜索出結(jié)果。。留下印子不忘記。。歡迎指正2012-11-11PHP跳出for循環(huán)中的break和continue
在PHP中,可以使用break關(guān)鍵字來跳出循環(huán),,PHP中還可以使用continue關(guān)鍵字跳過本次循環(huán)并繼續(xù)執(zhí)行下一次循環(huán),當(dāng)循環(huán)執(zhí)行到continue語句時(shí),本次循環(huán)中continue之后的代碼將不再執(zhí)行,直接進(jìn)入下一次循環(huán)2023-09-09在PHP中養(yǎng)成7個(gè)面向?qū)ο蟮暮昧?xí)慣
在 PHP 編程早期,PHP 代碼在本質(zhì)上是限于面向過程的。過程代碼 的特征在于使用過程構(gòu)建應(yīng)用程序塊。過程通過允許過程之間的調(diào)用提供某種程度的重用。2010-01-01PHP實(shí)現(xiàn)文件分片上傳的實(shí)例代碼
在本篇文章里小編給大家整理的是一篇關(guān)于PHP實(shí)現(xiàn)文件分片上傳的實(shí)例代碼內(nèi)容,有興趣的朋友們參考學(xué)習(xí)下。2020-01-01PHP簡(jiǎn)單實(shí)現(xiàn)無限級(jí)分類的方法
這篇文章主要介紹了PHP簡(jiǎn)單實(shí)現(xiàn)無限級(jí)分類的方法,涉及sql語句及遞歸調(diào)用的相關(guān)技巧,需要的朋友可以參考下2016-05-05mysqli擴(kuò)展無法在PHP7下升級(jí)問題的解決
這篇文章主要給大家介紹了關(guān)于mysqli擴(kuò)展無法在PHP7下升級(jí)問題的解決方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用PHP7具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09基于PHP實(shí)現(xiàn)堆排序原理及實(shí)例詳解
這篇文章主要介紹了基于PHP實(shí)現(xiàn)堆排序原理及實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06