Jump to content

[SOLVED] bb code help


SyncViews

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/100888-solved-bb-code-help/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/100888-solved-bb-code-help/#findComment-515975
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.