naf Posted June 7, 2010 Share Posted June 7, 2010 <?php function forumbbcode($text) { if(preg_match("/\[/", $text)) { $match = array( '/\[b\](.+?)\[\/b\]/is', '/\[u\](.+?)\[\/u\]/is', '/\[i\](.+?)\[\/i\]/is', '/\[url=(.+?)\](.+?)\[\/url\]/is', '/\[url\](.+?)\[\/url\]/is', '/\[quote\](.+?)\[\/quote\]/is' ); $replace = array( '<b>$1</b>', '<u>$1</u>', '<i>$1</i>', '<a href="$1">$2</a>', '<a href="$1">$1</a>', '<div class="quote">$1</div>' ); return preg_replace($match, $replace, $text); } } ?> I have this kind of BBCode parser, but only problem is that it doesn't allow for ex. multiple quotes inside. if i put [quote]asd[quote]efg[/quote][/quote] it will return <div class="quote">asd[quote]efg[/quote]</div> Quote Link to comment Share on other sites More sharing options...
ignace Posted June 7, 2010 Share Posted June 7, 2010 $count = 0; do { $text = preg_replace($match, $replace, $text, -1, $count); } while (0 < $count); Quote Link to comment Share on other sites More sharing options...
naf Posted June 7, 2010 Author Share Posted June 7, 2010 $count = 0; do { $text = preg_replace($match, $replace, $text, -1, $count); } while (0 < $count); Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.