0

Okay, I'm currently trying to create bbcodes for my home made forum. It worked good, until I started with quotes. This is my function:

public function forum_parse ($string)
{
    global $core, $path;
    $string = $this -> normal_parse ($string);

    $search = '/\[quote=([A-z0-9 -_\'"]+);([0-9]+)\](.*)\[\/quote\]/is';
    $replace = '<div class="quote"><p class="quote-author"><a href="' . $path . 'forum/viewtopic?p=$2">' . WRITTEN_BY . ' $1</a></p><p class="quote-content">$3</p></div>';

    return preg_replace ($search, $replace, $string);
}

It works good when there's one quote per post, but when there's more, the problems begin. It obviously doesn't start from the root quote and choose accurate end tags by itself. And I' not experienced with RegEx enough to fix it. Any help? :/

DCoder
  • 12,962
  • 4
  • 40
  • 62
SnackerSWE
  • 649
  • 1
  • 10
  • 19

1 Answers1

0

.* will consume as much as it can. Changing it to .*? will make it consume as little as it can, which should fix the problem ... just as long as you don't consider nested quotes.

A better solution, I believe, would be to use the answers to this post instead of inventing your own.

Community
  • 1
  • 1
DCoder
  • 12,962
  • 4
  • 40
  • 62