htmlpurifier  4.7.0
About: HTML Purifier is an HTML filtering solution. It tries to remove all malicious code (XSS) and to make sure the HTML is standards compliant.
  Fossies Dox: htmlpurifier-4.7.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

htmlpurifier Documentation

HTML Purifier is an HTML filter that will take an arbitrary snippet of HTML and rigorously test, validate and filter it into a version that is safe for output onto webpages. It achieves this by:

  1. Lexing (parsing into tokens) the document,
  2. Executing various strategies on the tokens:
    1. Removing all elements not in the whitelist,
    2. Making the tokens well-formed,
    3. Fixing the nesting of the nodes, and
    4. Validating attributes of the nodes; and
  3. Generating HTML from the purified tokens.

However, most users will only need to interface with the HTMLPurifier and HTMLPurifier_Config.