HTML Purifier will not only remove all malicious code with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant.