如何修复bb代码的代码问题

时间:2013-06-25 16:01:07

标签: php bbcode

我的bb代码有问题。我有一个函数,它将bbcode替换为php代码

public static function decodeBB($text)
{
    $text = nl2br($text);
    $text = preg_replace('/\[b\](.*)\[\/b\]/Usi', '<b>$1</b>', $text);
    $text = preg_replace('/\[i\](.*)\[\/i\]/Usi', '<i>$1</i>', $text);
    $text = preg_replace('/\[s\](.*)\[\/s\]/Usi', '<s>$1</s>', $text);
    $text = preg_replace('/\[u\](.*)\[\/u\]/Usi', '<u>$1</u>', $text);
    $text = preg_replace('/\[quote\](.*)\[\/quote\]/Usi', '<div>Quote:</div><span style=\"border:solid 1px;background-color: white;\">$1</span>', $text);
    $text = preg_replace("/\[url=(?:&#039;|&quot;|\'|\")(((ht|f)tps?:(?:\/\/)?)(?:[^<\s\'\"]+))(?:&#039;|&quot;|\'|\")\](.*)\[\/url\]/Usi", "<a href=\"$1\">$4</a>", $text);
    $text = preg_replace("/\[img\](((ht|f)tps?:(?:\/\/)?)(?:[^<\s\'\"]+))\[\/img\]/Usi", "<img src=\"$1\">", $text);
    $text = preg_replace("/(?<!:&#039;|&quot;|\'|\"|\])(((ht|f)tp(s)?:\/\/)([^<\s\'\"]+))(?<!:&#039;|&quot;|\'|\"|\[)/is", "<a href=\"$1\">$1</a>", $text);

    $text = self::BBquote($text);

    return $text;
}

当文字写成这样的时候,[quote] [/ quote]有问题:

[quote]Hello[/quote]

这样可行,但是当它写成这样的时候它不起作用:

[quote][quote]Hello[/quote]How are you?[/quote]

但是其他代码工作正常,有人知道如何解决这个问题吗?

0 个答案:

没有答案