欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php UBB 解析实现代码

程序员文章站 2023-11-03 19:55:22
复制代码 代码如下: /** +---------------------------------------------------------- * ubb 解析 +-...
复制代码 代码如下:

/**
+----------------------------------------------------------
* 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;
}