title: PHP Check For Matching Tags In User Submitted Content
body: <p>I've been putting together my own customly made forum using PHP, and it's coming along astoundingly, but I was trying to figure out if there is a way to check for matching BBCode tags? I have my own arrays set up to replace <code>&lt;b&gt;</code> with <code>[b]</code> and so on, but I want to be able to make sure that the tags will be closed at some point <code>[/b]</code> and not continue to run off of the post and onto the rest of the page.</p>
  
  <p>For example: <code>[b]This is text</code> will show up as <code>[b]This is text</code>, and <code>[b]This is text[/b]</code> will return on the page as <code>&lt;b&gt;This is text&lt;/b&gt;</code></p>
  
  <p>Is there a way to do this, or is there a way in PHP/HTML to 'escape' any opened tags? IE; if no <code>[/b]</code> is in the post, automatically add a <code>&lt;/b&gt;</code> onto the end of it.</p>