I developed a class that allows me to have control over many BBCode tags and other special formats and is working well. The issue I'm having is having inner tags the same as an outer tag. For example, a [quote][/quote] within another [quote][/quote] like this:
[quote=Foo]Here is a quote:
[quote=Bar]Test[/quote]
Did that work?[/quote]
The issue is that the regex is finding the inner end [/quote] when it's finding a match for the outer start [quote].
Would I have to split and go line by line to find proper matches or is there an elegant way of doing this?
Here is a small test of how I'm doing it (there is a bit more but functionally this is all it's doing):
$desc = '[quote=Foo]Here is a quote:
[quote=Bar]Test[/quote]
Did that work?[/quote]';
$args = array(
'tid' => 1234
);
preg_match('`\[(quote)=?(.*?)\]((\r\n|\r|\n|.)+?)\[\/quote\]`i', $desc, $matches);
list($str, $tag, $match, $innertext) = $matches;
$params = explode(';', $match);
$name = array_shift($params);
$replacement = '<div class="quote">' . $name . '<span class="quote-text">' . $innertext . '</span></div>';
$string = str_replace($str, $replacement, $desc);
Other tags are fine when they are nested within others, just the like tags are finding the match incorrectly.