自定義ubb代碼,preg_replace()函數(shù)的一些代碼
更新時(shí)間:2007年03月20日 00:00:00 作者:
function ubb($Text) {
$Text=htmlspecialchars($Text);
$Text=ereg_replace("\r\n","<br>",$Text);
$Text=ereg_replace("\r","<br>",$Text);
$Text=nl2br($Text);
$Text=preg_replace("/\\t/is"," ",$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("/\[url\](http:\/\/.+?)\[\/url\]/is","<a href=\\1>\\1</a>",$Text);
$Text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"http://\\1\">http://\\1</a>",$Text);
$Text=preg_replace("/\[url=(http:\/\/.+?)\](.*)\[\/url\]/is","<a href=\\1>\\2</a>",$Text);
$Text=preg_replace("/\[url=(.+?)\](.*)\[\/url\]/is","<a href=http://\\1>\\2</a>",$Text);
$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\\1>",$Text);
$Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$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("/\[email\](.+?)\[\/email\]/is","<a href=\\1>\\1</a>",$Text);
$Text=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$Text);
$Text=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$Text);
$Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote><font size='2' face='Courier New'>quote:</font><hr>\\1<hr></blockquote>", $Text);
$Text=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><font size='2' face='Courier New'>code:</font><hr color='lightblue'><i>\\1</i><hr color='lightblue'></blockquote>", $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;
}
function str($msg){
global $admin;
if(!$admin[html]) $msg=htmlspecialchars($msg);
if($admin[ubb]) $msg=ubb($msg);
$msg=nl2br($msg); #處理message
$msg= str_replace("\n","",$msg); #處理message
$msg= str_replace("\r","",$msg); #處理message
return $msg;
}
function error($msg){
global $admin;
?>
中的
$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
里面的 ("/\[h2](.+?)\[\/h2]/is","<h2>\\1</h2>",$text)
/\[h2](.+?)\[\/h2]/is 轉(zhuǎn)化成 <h2>\\1</h2>
/\[h2](.+?)\[\/h2]/is 里面的 這些"/\(.+?)\ "之類的符號(hào)是怎么看的?是什么意思?
______________________________________________________________________________________________
\是轉(zhuǎn)意,\本身是特殊符號(hào),如果要作為普通字符就要用\來轉(zhuǎn)意,就是說\\表示()也是特殊符號(hào),所以要用\轉(zhuǎn)意
$Text=htmlspecialchars($Text);
$Text=ereg_replace("\r\n","<br>",$Text);
$Text=ereg_replace("\r","<br>",$Text);
$Text=nl2br($Text);
$Text=preg_replace("/\\t/is"," ",$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("/\[url\](http:\/\/.+?)\[\/url\]/is","<a href=\\1>\\1</a>",$Text);
$Text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"http://\\1\">http://\\1</a>",$Text);
$Text=preg_replace("/\[url=(http:\/\/.+?)\](.*)\[\/url\]/is","<a href=\\1>\\2</a>",$Text);
$Text=preg_replace("/\[url=(.+?)\](.*)\[\/url\]/is","<a href=http://\\1>\\2</a>",$Text);
$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\\1>",$Text);
$Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$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("/\[email\](.+?)\[\/email\]/is","<a href=\\1>\\1</a>",$Text);
$Text=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$Text);
$Text=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$Text);
$Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote><font size='2' face='Courier New'>quote:</font><hr>\\1<hr></blockquote>", $Text);
$Text=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><font size='2' face='Courier New'>code:</font><hr color='lightblue'><i>\\1</i><hr color='lightblue'></blockquote>", $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;
}
function str($msg){
global $admin;
if(!$admin[html]) $msg=htmlspecialchars($msg);
if($admin[ubb]) $msg=ubb($msg);
$msg=nl2br($msg); #處理message
$msg= str_replace("\n","",$msg); #處理message
$msg= str_replace("\r","",$msg); #處理message
return $msg;
}
function error($msg){
global $admin;
?>
中的
$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
里面的 ("/\[h2](.+?)\[\/h2]/is","<h2>\\1</h2>",$text)
/\[h2](.+?)\[\/h2]/is 轉(zhuǎn)化成 <h2>\\1</h2>
/\[h2](.+?)\[\/h2]/is 里面的 這些"/\(.+?)\ "之類的符號(hào)是怎么看的?是什么意思?
______________________________________________________________________________________________
\是轉(zhuǎn)意,\本身是特殊符號(hào),如果要作為普通字符就要用\來轉(zhuǎn)意,就是說\\表示()也是特殊符號(hào),所以要用\轉(zhuǎn)意
相關(guān)文章
使用正則表達(dá)式判斷是否為手機(jī)號(hào)碼(簡單且實(shí)用)
這篇文章主要介紹了使用正則表達(dá)式判斷是否為手機(jī)號(hào)碼(簡單且實(shí)用)的相關(guān)知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看下吧2016-11-11
一個(gè)容易犯錯(cuò)的js手機(jī)號(hào)碼驗(yàn)證正則表達(dá)式(推薦)
這篇文章主要介紹了 一個(gè)容易犯錯(cuò)的js手機(jī)號(hào)碼驗(yàn)證正則表達(dá)式(推薦),需要的朋友可以參考下2017-03-03
javascript正則表達(dá)式和字符串RegExp and String(一)
這篇文章主要介紹了javascript正則表達(dá)式和字符串RegExp and String(一)的相關(guān)資料,需要的朋友可以參考下2015-10-10
學(xué)習(xí)正則表達(dá)式30分鐘入門教程(第二版)
30分鐘內(nèi)讓你明白正則表達(dá)式是什么,并對它有一些基本的了解,讓你可以在自己的程序或網(wǎng)頁里使用它2007-03-03
JavaScript中常用的正則表達(dá)式日常整理(全)
本篇文章是小編日常整理有關(guān)js常用的正則表達(dá)式,比較全面,對大家學(xué)習(xí)javascript正則表達(dá)式非常有用,需要的朋友一起學(xué)習(xí)吧2015-09-09

