SyncViews Posted April 13, 2008 Share Posted April 13, 2008 Ive made these to process bb codes: <?php $bb_codes = array( '/\[b\](.*?)\[\/b\]/is', //BOLD '/\[i\](.*?)\[\/i\]/is', //ITALIC '/\[u\](.*?)\[\/u\]/is', //UNDERLINE '/\[url\](.*?)\[\/url\]/is', //URL '/\[url\=(.*?)\](.*?)\[\/url\]/is', //URL2 '/\[img\](.*?)\[\/img\]/is', //IMAGE '/\[mail\](.*?)\[\/img\]/is', //MAIL '/\[mail\=(.*?)\](.*?)\[\/mail\]/is', //MAIL2 '/\[colo?r\=(.*?)\](.*?)\[\/colo?r\]/is', //COLOUR '/\[size\=(.*?)\](.*?)\[\/size\]/is', //SIZE '/\[font\=(.*?)\](.*?)\[\/font\]/is', //FONT '/\[align\=(left|center|right)\](.*?)\[\/align\]/is', //ALIGN '/\[pre\](.*?)\[\/pre\]/is' //PREFORMATTED ); $bb_html = array( '<span style="font-weight: bold">$1</span>', //BOLD '<span style="font-style: italic">$1</span>', //ITALIC '<span style="text-decoration: underline">$1</span>', //UNDERLINE '<a href="$1">$1</a>', //URL '<a href="$1">$2</a>', //URL2 '<img src="$1" alt="$1" />', //IMAGE '<a href="mailto:$1">$1</a>', //MAIL '<a href="mailto:$1">$2</a>', //MAIL2 '<span style="color: $1">$2</span>', //COLOUR '<span style="font-size: $1">$2</span>', //SIZE '<span style="font-family: $1">$2</span>', //FONT '<span style="text-align: $1">$2</span>', //ALIGN '<pre>$1</pre>' //PREFORMATTED ); $str = preg_replace ($bb_codes, $bb_html, $str); ?> The problem I'm havin is how to process the [code][/code] tags as I need to stop any of the other bbcodes effecting the code block. Quote Link to comment https://forums.phpfreaks.com/topic/100888-solved-bb-code-help/ Share on other sites More sharing options...
laffin Posted April 13, 2008 Share Posted April 13, 2008 either 1 rip out the code block, and re-insert at end of bbcode procedures. or convert a codeblock [ ] < > with their html entities conterpart Quote Link to comment https://forums.phpfreaks.com/topic/100888-solved-bb-code-help/#findComment-515965 Share on other sites More sharing options...
Daniel0 Posted April 13, 2008 Share Posted April 13, 2008 You could do split it up and only apply the parsing on specific parts of the content. I cannot post the code here because it will break the parsing in SMF's post parser, so I uploaded it here: http://phpfreaks.com/daniel/bbcode_parsing.phps <b>bold</b> <pre>[b]not bold[/b] because it's inside code tags</pre> Quote Link to comment https://forums.phpfreaks.com/topic/100888-solved-bb-code-help/#findComment-515975 Share on other sites More sharing options...
SyncViews Posted April 13, 2008 Author Share Posted April 13, 2008 Thanks that does what I want Quote Link to comment https://forums.phpfreaks.com/topic/100888-solved-bb-code-help/#findComment-515985 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.