Using tidy_clean_repair()
<?php $tidy = tidy_parse_string("<B>This is a simple,</I> but <B>malformed</B> <U>HTML Document<U>"); tidy_clean_repair($tidy); echo $tidy; ?>