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> Link to comment https://forums.phpfreaks.com/topic/204086-bbcode-help/ 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); Link to comment https://forums.phpfreaks.com/topic/204086-bbcode-help/#findComment-1068935 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. Link to comment https://forums.phpfreaks.com/topic/204086-bbcode-help/#findComment-1069016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.