HtmlPurifier is a standards-compliant HTML filter library written in PHP. HTML Purifier 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. [...] Although Codeigniter comes with it's own XSS filtering method, I prefer the use of the HtmlPurifier.
Installation is simple, involving only a four step process (including the download) and using it is just as easy. It's (basically) just a matter of loading the library and calling the purify method to output the corrected HTML.