OK I have added bbcode to a script and everthing works fine but now what I need to do is add

 tags to format code. I can format the text between the code tags anyway I want but what I'm having trouble doing is stoping bb tags outside the code tags from formating the text inside the code tags. 

Example: 
on this forum if I type {b} in brackets here >>
[b] this is bold text
[code=php]then text inside the PHP tags is not bold but the bold text continues after the ending PHP tag 

text is still bold after the PHP tags
[/b]{/b}

I would really appreciate any help getting this to work!!

Here is the bbcode function I'm using ([ code] tages are not included because I don't know where to start).
Please ignore the spaces in the patterns array because this forum formats the bbtags inside the PHP tags.

function bbcode($string){
$patterns = array(
'`\[ b\](.+?)\[/b\]`is',
'`\[ i\](.+?)\ /i\]`is',
'`\[ u\](.+?)\[/ u\]`is',
'`\[ strike\](.+?)\[/ strike\]`is',
'`\[ color=#([0-9A-Fa-f]{6})\](.+?)\[/color\]`is',
'`\[ email\](.+?)\[/email\]`is',
'`\[ img\](.+?)\[/img\]`is',
'`\[ url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si',
'`\[ url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si',
'`\[ url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si',
'`\[ flash=([0-9]+),([0-9]+)\](.+?)\[/flash\]`is',
'`\[ quote\](.+?)\[/quote\]`is',
'`\[ indent](.+?)\[/indent\]`is',
'`\[ size=([1-6]+)\](.+?)\[/size\]`is'
);

$replaces =  array(
'<strong>\\1</strong>',
'<em>\\1</em>',
'<span style="border-bottom: 1px dotted">\\1</span>',
'<strike>\\1</strike>',
'<span style="color:#\1;">\2</span>',
'<a href="mailto:\1">\1</a>',
'<img src="\1" alt="" style="border:0px;" />',
'<a href="\1\2">\6</a>',
'<a href="\1\2">\1\2</a>',
'<a href="http://\1">\1</a>',
'<object width="\1" height="\2"><param name="movie" value="\3" /><embed src="\3" width="\1" height="\2"></embed></object>',
'<br /><strong>Quote:</strong><div style="margin:0px 10px;padding:5px;background-color:#F7F7F7;border:1px dotted #CCCCCC;"><em>\1</em></div>',
'<pre>\\1</pre>',
'<h\1>\2</h\1>'

);


$prev_string = "";
while ($prev_string != $string){
	$prev_string = $string;
	$string = preg_replace($patterns, $replaces , $string);
}
return $string;
}
    Write a Reply...