看看ctb里的替换。。<?php
$str = "welcome to Csdn.Net !";
echo ubb($str);function ubb($msg){
        $search_array = array(
            "/\[code](.*)\[\/code]/isU",
            "/\
Quote:
(.*)\[\/quote]/isU",
            "/\[img]([^'\"\?\&\+]*(\.gif|jpg|jpeg|png|bmp))\[\/img]/iU",
            "/\[img=([^'\"\?\&\+]*(\.gif|jpg|jpeg|png|bmp))]([^'\"]*)\[\/img]/iU",
            "/\[url]www.([^'\"]*)\[\/url]/iU",
            "/\[url]([^'\"]*)\[\/url]/iU",
            "/\[url=www.([^'\"\s]*)](.*)\[\/url]/iU",
            "/\[url=([^'\"\s]*)](.*)\[\/url]/iU",
            "/\[email]([^'\"\s]*)\[\/email]/iU",
            "/\[email=([^'\"\s]*)](.*)\[\/email]/iU",
            "/\[b](.*)\[\/b]/isU",
            "/\[i](.*)\[\/i]/isU",
            "/\[u](.*)\[\/u]/isU",
            "/\[size=([1-7])](.*)\[\/size]/isU",
            "/\[color=(#?[\da-fA-F]{6})](.*)\[\/color]/isU",
            "/\[color=([a-zA-Z]{3,20})](.*)\[\/color]/isU",
            "/\[font=([^'\"]*)](.*)\[\/font]/isU",
            "/\[center](.*)\[\/center]/isU",
            "/\[right](.*)\[\/right]/isU",
            "/\[shadow](.*)\[\/shadow]/isU",
            "/\[glow](.*)\[\/glow]/isU",
            "/\[fly](.*)\[\/fly]/isU",
            "/\[move](.*)\[\/move]/isU",
            "/\[swf]www.([^'\"\s]*)\[\/swf]/iU",
            "/\[swf]([^'\"\s]*)\[\/swf]/iU",
            "/\[swf width=([1-6]\d\d) height=([1-9]\d\d)]www.([^'\"\s]*)\[\/swf]/iU",
            "/\[swf width=([1-6]\d\d) height=([1-9]\d\d)]([^'\"\s]*)\[\/swf]/iU",
            "/\[mp]([^'\"\s]*)\[\/mp]/iU",
            "/\[rp]([^'\"\s]*)\[\/rp]/iU",
        );        $replace_array = array(
            "<center>代码:<br /><table cellpadding=\"4\" cellspacing=\"1\" class=\"tInner\"><tr class=\"tBody2\"><td style=\"WORD-BREAK: break-all\">\\1</td></tr></table></center>",
            "<center>引用:<br /><table cellpadding=\"4\" cellspacing=\"1\" class=\"tInner\"><tr class=\"tBody2\"><td style=\"WORD-BREAK: break-all\">\\1</td></tr></table></center>",
            " <img src=\"\\1\" alt=\"User's Image\" onload=\"if(this.width>screen.width-750) this.width=screen.width-750;\" onmouseover=\"this.style.cursor='hand';\" onclick=\"window.open('\\1');\" /> ",
            " <img src=\"\\1\" alt=\"\\3\" onload=\"if(this.width>screen.width-750) this.width=screen.width-750;\" onmouseover=\"this.style.cursor='hand';\" onclick=\"window.open('\\1');\" /> ",
            "<a href=\"http://www.\\1\" target=\"_blank\">www.\\1</a>",
            "<a href=\"\\1\" target=\"_blank\">\\1</a>",
            "<a href=\"http://www.\\1\" target=\"_blank\">\\2</a>",
            "<a href=\"\\1\" target=\"_blank\">\\2</a>",
            "<a href=\"mailto:\\1\">\\1</a>",
            "<a href=\"mailto:\\1\">\\2</a>",
            "<b>\\1</b>",
            "<i>\\1</i>",
            "<u>\\1</u>",
            "<font size=\"\\1\">\\2</font>",
            "<font color=\"\\1\">\\2</font>",
            "<font color=\"\\1\">\\2</font>",
            "<font face=\"\\1\">\\2</font>",
            "<center>\\1</center>",
            "<div align=\"right\">\\1</div>",
            "<table style=\"filter: shadow(color='#ff5555', direction='135')\"><nobr><font color=\"ffffff\">\\1</font></nobr></table>",
            "<table style=\"filter: glow(color='#5555ff', strength='4')\"><nobr><font color=\"ffffff\">\\1</font></nobr></table>",
            "<marquee behavior=\"alternate\">\\1</marquee>",
            "<marquee>\\1</marquee>",
            "<embed src=\"http://www.\\1\" width=\"400\" height=\"300\"></embed><br />",
            "<embed src=\"\\1\" width=\"400\" height=\"300\"></embed><br />",
            "<embed src=\"http://www.\\3\" width=\"\\1\" height=\"\\2\"></embed><br />",
            "<embed src=\"\\3\" width=\"\\1\" height=\"\\2\"></embed><br />",
            "<br /><object classid=\"clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6\" name=\"MediaPlayer\" codeBase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,1,5,217\" type=\"application/x-oleobject\" standby=\"Loading Microsoft Windows Media Player components...\" width=\"360\" height=\"300\"><param name=\"URL\" value=\"\\1\"><param name=\"autostart\" value=\"false\"></object><br />",
            "<br /><object classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" width=\"360\" height=\"240\"><param name=\"src\" value=\"\\1\"><param name=\"controls\" value=\"ImageWindow\"><param name=\"console\" value=\"console_$this->i\"><param name=\"autostart\" value=\"false\"></object><br /><object classid=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" width=\"360\" height=\"100\"><param name=\"controls\" value=\"All\"><param name=\"console\" value=\"console_$this->i\"></object><br />",
        );        $msg = preg_replace($search_array, $replace_array, $msg);
return $msg;
}
?>