Close all open HTML tags

I want users to be able to input some HTML styling on their site.

However, if they leave tags open such as <b>, the rest of the site get’s kindof funny formatting.

I’m loading in the data using PHP. Is there any way to close all HTML tags that still lay open?