I use php tidy to process html input in my database,
$fragment = tidy_repair_string($dom->saveHTML(), array(\'output-xhtml\'=>1,\'show-body-only\'=>
HTML Purifier can rewrite HTML to be standards-compliant like HTML Tidy. If you need to filter that input for XSS prevention, etc., it will do that as well.
It's all PHP, so you should be able to use it on any server.