I create a bbcode parser
I used nl2br() when output.
But, why will be this result

input 

```
[table][tr][td]1[/td]
[td]2[/td]
[/tr]
[tr][td]3[/td]
[td]4[/td]
[/tr]
[/table]

[ul]
[li]1[/li]
[li]2[/li]
[li]3[/li]
[/ul]

[ol]
[li]A[/li]
[li]B[/li]
[li]C[/li]
[/ol]

```

output

```
<br><br><br><br><br><br><table><tbody><tr><td>1</td>
<td>2</td>
</tr>
<tr><td>3</td>
<td>4</td>
</tr>
</tbody></table><br>
<br>
<ul><br>
<li>1</li><br>
<li>2</li><br>
<li>3</li><br>
</ul><br>
<br>
<ol><br>
<li>A</li><br>
<li>B</li><br>
<li>C</li><br>
</ol><br>

```

my php function

```
function showBBcodes($text) {

     $text = htmlspecialchars($text);
     preg_match_all('#\[code\](.*?)\[/code]#is', $text, $stack);  

    // BBcode array
    $find = array(
        '~\[ul\](.*?)\[/ul\]~s',
        '~\[li\](.*?)\[/li\]~s',
        '~\[ol\](.*?)\[/ol\]~s',
        '~\[table\](.*?)\[/table\]~s',
        '~\[tr\](.*?)\[/tr\]~s',
        '~\[td\](.*?)\[/td\]~s',
        '~\[img\](.*?)\[/img\]~s',
        '/\[img=(\d+)x(\d+)\](.*?)\[\/img\]/is'
    );

    // HTML tags to replace BBcode
    $replace = array(
        '<ul>$1</ul>',
        '<li>$1</li>',
        '<ol>$1</ol>',
        '<table>$1</table>',
        '<tr>$1</tr>',
        '<td>$1</td>',
        '<img src="$1" alt=""/>',
        '<img width="$1" height="$2" src="$3" alt="" />'
    );       
    $text = preg_replace($find,$replace,$text);
    $text = nl2br($text);

    foreach($stack[1] as $t) {
      $text = preg_replace('#\[code\].*?\[/code]#is','<div class="code_box">'.$t.'</div>', $text,1); 
    }
    return $text;
}

```

My test:
Between [ table ] and [/ table], show six times \n.
so Before [table] appeared six times   

how can I fixed that?

can I skip not use nl2br in [table] [ul] [li] but use in [tr] [li]??

or anyone can give me more suggest

thanks.