htmLawed is a highly customizable single-file PHP script to make text secure, and standard- and admin policy-compliant for use in the body of HTML, XHTML or generic XML documents. It is thus filter, processor, purifier, sanitizer, beautifier, etc., and an alternative to HTMLTidy.
htmLawed ensures that HTML code in the text is standard-compliant, does not introduce security vulnerabilities, and does not break the aesthetics, design or layout of web-pages. htmLawed tries to do this by, for example, making HTML well-formed with balanced and properly nested tags, neutralizing code that may be used for cross-site scripting (XSS) attacks, and allowing specified tags & attributes.
It is used to filter blog comments & forum posts, generate XML-compatible feed items, make old HTML XHTML-compliant, pretty-print HTML, scrape web-pages, etc.
Compared to HTMLPurifier, it has full HTML coverage, is 10-15x smaller in size & memory use, faster and PHP 4-compatible.