I already know how XSS works, but finding out all the many different ways to inject malicious input is not an option.
I saw a couple libraries out there, but most of
HTMLPurifier is the undenied best option for cleansing HTML input, and htmlspecialchars should be applied to anything else.
But XSS vulnerabilities should not be cleaned out, because any such submissions are garbage anyway. Rather make your application bail and write a log entry. The best filter set to achieve XSS detection is in the mod_security core rules.
I'm using an inconspicious but quite thorough attribute detection here in new input(), see _xss method.