I am constructing a large HTML document from fragments supplied by users that have the annoying habit of being malformed in various ways. Browsers are robust and forgiving enough but I want to be able to validate and (ideally) fix any malformed HTML if at all possible. For example:
<td><b>Title</td>
can be reasonably fixed to:
<td><b>Title</b></td>
Is there a way of doing this easily in PHP?
If you can't use Tidy (sometimes hosting service do not activate this php module), you can use this PHP class: http://www.barattalo.it/html-fixer/
You can use HTML Tidy, man pages are here.
I highly recommend HTML Purifier. From their site: