我正在制作一个网站,用户可以在其中输入一些 BBcode 和我的 owan BBcode
但是当引号内有引号时我遇到了问题
例如 :
[quote] [quote] 正文一 [/quote] 正文二 [/quote]
预期结果:
---------------------------- | | | ------------------------------------ | | |文字一 | | | ------------------------------------ | | | |文本二 | ----------------------------
真正的结果:
---------------------------- |[quote]正文一 | ---------------------------- 正文二 [/quote]
我的代码:
function bbcode($replace)
{
$bbcode = array(
"'\[center\](.*?)\[/center\]'is" => "<center>\\1</center>",
"'\[left\](.*?)\[/left\]'is" => "<div style='text-align: left;'>\\1</div>",
"'\[right\](.*?)\[/right\]'is" => "<div style='text-align: right;'>\\1</div>",
"'\[pre\](.*?)\[/pre\]'is" => "<pre>\\1</pre>",
"'\[b\](.*?)\[/b\]'is" => "<b>\\1</b>",
"'\[quote\](.*?)\[/quote\]'is" => "<div class='qrap'><small>Quote:</small><div class='quote'><br><br>\\1</div></div>",
"'\[i\](.*?)\[/i\]'is" => "<i>\\1</i>",
"'\[enter]'is" => "<br>",
"'\[u\](.*?)\[/u\]'is" => "<u>\\1</u>",
"'\[s\](.*?)\[/s\]'is" => "<del>\\1</del>",
"'\[move\](.*?)\[/move\]'is" => "<marquee>\\1</marquee>",
"'\[url\](.*?)\[/url\]'is" => "<a href='\\1' target='_BLANK'>\\1</a>",
"'\[url=(.*?)\](.*?)\[/url\]'is" => "<a href=\"\\1\" target=\"_BLANK\">\\2</a>",
"'\[img\](.*?)\[/img\]'is" => "<img border=\"0\" src=\"\\1\">",
"'\[img=(.*?)\]'" => "<img border=\"0\" src=\"\\1\">",
"'\[email\](.*?)\[/email\]'is" => "<a href='mailto: \\1'>\\1</a>",
"'\[size=(.*?)\](.*?)\[/size\]'is" => "<span style='font-size: \\1;'>\\2</span>",
"'\[font=(.*?)\](.*?)\[/font\]'is" => "<span style='font-family: \\1;'>\\2</span>",
"'\[color=(.*?)\](.*?)\[/color\]'is" => "<span style='color: \\1;'>\\2</span>",
"'\[youtube\](.*?)\[/youtube\]'is" => "<object height='350' width='425'><param name='movie' value='http://www.youtube.com/v/\\1'><embed src='http://www.youtube.com/v/\\1' type='application/x-shockwave-flash' wmode='transparent' height='350' width='425'></object>",
"'\[quote=(.*?)\](.*?)\[/quote\]'is" => "<div class='qrap'><small>Quote:</small><div class='quote'>Originally posted by: <b>\\1</b><br><br>\\2</div></div>",
"'\[spoiler\](.*?)\[/spoiler\]'is" => "<div class='srap'>
<div><b>Spoiler</b>: <input type='button' onclick='spoiler(this)' value='SHOW' class='sbutton'></div>
<div>
<div class='spoiler' style='display:none;'>\\1</div>
</div>
</div>",
"'\[spoiler=(.*?)\](.*?)\[/spoiler\]'is" => "<div class='srap'>
<div><b>Spoiler</b> for <i>\\1</i>: <input type='button' onclick='spoiler(this)' value='SHOW' class='sbutton'></div>
<div>
<div class='spoiler' style='display:none;'>\\2</div>
</div>
</div>",
"'\[quotepost=(.*?);(.*?)\](.*?)\[/quote\]'is" => "<div class='qrap'><small>Quote:</small><div class='quote'>Originally posted by: <b>\\1</b> (<a href=\"viewcomment.php?id=\\2\" target='_BLANK'>Go to Post</a>)<br><br>\\3</div></div>"
);
$replace = preg_replace(array_keys($bbcode), array_values($bbcode), $replace);
return $replace;
}
?>
有人能帮我吗?提前致谢