php ubb代碼解析程式_PHP教程

來源:互聯網
上載者:User
文章給你分享一篇簡單的關於ubb代碼如何利用php來解析哦,我們主要用到了preg_replace()函數,有了其它一切都好做
代碼如下 複製代碼

/**
+----------------------------------------------------------
* UBB 解析
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
function ubb($Text) {
$Text=trim($Text);
$Text=ereg_replace("n","
",$Text);
$Text=preg_replace("/\t/is"," ",$Text);
$Text=preg_replace("/[hr]/is","",$Text);
$Text=preg_replace("/[separator]/is","
",$Text);
$Text=preg_replace("/[h1](.+?)[/h1]/is","

\1

",$Text);
$Text=preg_replace("/[h2](.+?)[/h2]/is","

\1

",$Text);
$Text=preg_replace("/[h3](.+?)[/h3]/is","

\1

",$Text);
$Text=preg_replace("/[h4](.+?)[/h4]/is","

\1

",$Text);
$Text=preg_replace("/[h5](.+?)[/h5]/is","
\1
",$Text);
$Text=preg_replace("/[h6](.+?)[/h6]/is","
\1
",$Text);
$Text=preg_replace("/[center](.+?)[/center]/is","\1",$Text);
//$Text=preg_replace("/[url=([^[]*)](.+?)[/url]/is","\2",$Text);
$Text=preg_replace("/[url](.+?)[/url]/is","\1",$Text);
$Text=preg_replace("/[url=(http://.+?)](.+?)[/url]/is","\2",$Text);
$Text=preg_replace("/[url=(.+?)](.+?)[/url]/is","\2",$Text);
$Text=preg_replace("/[img](.+?)[/img]/is","",$Text);
$Text=preg_replace("/[imgs(.+?)](.+?)[/img]/is","",$Text);
$Text=preg_replace("/[color=(.+?)](.+?)[/color]/is","\2",$Text);
$Text=preg_replace("/[colorTxt](.+?)[/colorTxt]/eis","color_txt('\1')",$Text);
$Text=preg_replace("/[style=(.+?)](.+?)[/style]/is","\2",$Text);
$Text=preg_replace("/[size=(.+?)](.+?)[/size]/is","\2",$Text);
$Text=preg_replace("/[sup](.+?)[/sup]/is","\1",$Text);
$Text=preg_replace("/[sub](.+?)[/sub]/is","\1",$Text);
$Text=preg_replace("/[pre](.+?)[/pre]/is","
\1
",$Text);
$Text=preg_replace("/[emot](.+?)[/emot]/eis","emot('\1')",$Text);
$Text=preg_replace("/[email](.+?)[/email]/is","\1",$Text);
$Text=preg_replace("/[i](.+?)[/i]/is","\1",$Text);
$Text=preg_replace("/[u](.+?)[/u]/is","\1",$Text);
$Text=preg_replace("/[b](.+?)[/b]/is","\1",$Text);
$Text=preg_replace("/[quote](.+?)[/quote]/is","
引用:\1
", $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","

--------------------------
\1
--------------------------", $Text);
return $Text;
}

關於preg_replace()函數文法

preg_replace函數基礎與執行個體代碼
//preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) 主題為匹配搜尋模式,替換替換
/*
要搜尋的模式。它可以是一個字串或一個字串數組。

電子修飾符使preg_replace函數()替代治療後,適當引用作為參數是php教程代碼進行替換。提示:請確保置換構成一個有效php代碼字串,否則php將抱怨在包含preg_replace函數線()解析錯誤。

傳回值

preg_replace函數()返回一個數組,如果這個問題的參數是一個數組或一個字串,否則。

如果找到匹配,新問題會產生,否則將返回主題不變或null如果發生錯誤。


更多詳細內容請查看:http://www.bKjia.c0m/phper/php-function/33530.htm

http://www.bkjia.com/PHPjc/631672.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631672.htmlTechArticle文章給你分享一篇簡單的關於ubb代碼如何利用php來解析哦,我們主要用到了preg_replace()函數,有了其它一切都好做 代碼如下 複製代碼 /** +...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.