With Tidy, complying with web standards is easy
Tidy has a great markup parser which intelligently corrects a wide range of errors:

Input HTML
<P>Hello, <B>This HTML</I><I>is all sorts of</U></B> messed up!
Clean it up with Tidy
<?php
    $tidy 
tidy_parse_file("intro2_ex1.html");
    
tidy_clean_repair($tidy);    
    echo 
tidy_get_output($tidy);    
?>
Output HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title></title>
</head>
<body>
<p>Hello, <b>This HTML</b><i>is all sorts of</i> messed up!</p>
</body>
</html>