Open Source HTML Filter Library: HTML Purifier
Lcensed under the LGPL v2.1+, HTML Purifier is a open source HTML filter library written in PHP. It will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C’s specifications.
HTML Purifier is a great php library to integrate with existing CMS and other applications or WYSIWYG editors. Plugins for many web applications (WordPress, Joomla, Drupal and more) can be found.