PHP -> STRTR() function problem

Hi,
I’m making a function to replace in a textbox: ** for <b> … and that kind of thing… [br] for <br>… etc, so somaone can write smilefaces and then I can replace that by a image [:-)] => :smiley:

my function is:


function colorearTexto($str){
$RESERVED=array("**"=>"<b>","**"=>"</b>","
"=>"<br>"); //... etc
return strtr($str, $RESERVED);
}

My problem is… there is a way to count the number of “[” (in this case) so if they don’t match with the numer of “]” an error sintaxis appears… bicouse if someone write:

hello **my name is [/b
… etc etc blabla

and forgot the “]”, i don’t want that all the text appears in bold…

or there is another way??