There are a lot of cool people on the PHP Developer Network forums. One of them is Edward Z. Yang.

On June 20th, Edward released HTML Purifier 2.0.0. HTML Purifier is a standards compliant HTML filter written in PHP. It uses a whitelisting approach and outputs standards compliant code, even if originally scrambled into an unintellible mess. It uses functionality in the background based on Tidy’s behaviour (so your preferred DTD is adhered to while filtering).

It’s purpose, in case you’re not familiar with HTML filter libraries, is to filter HTML user input to ensure it only includes whitelisted elements and attributes, and absolutely no XSS. The site contains a page dedicated to tests against the infamous http://ha.ckers.org/xss.html exploits. There’s even a demo page for testing it against your own possible exploits.

For my own part, HTML Purifier is probably the finest HTML filtering library in PHP at the moment. Its design is top notch, it’s a doddle to extend, and the API is intuitive for whitelisting (see the Advanced API). The library’s website has a stock of documentation for users and developers – including some useful tips for improving performance. Go get a copy and give it a whirl.

Related posts:

  1. OpenID 2.0 Library – to PEAR, Zend or both?
  2. OpenID library for the Zend Framework?
  3. Refactoring an OpenID Library
  4. Filter Extension Issues – A Storm in a Teacup?
  5. YAML for the Zend Framework – well, maybe…