During this time and age, in order to fully and completely protect yourself from XSS, you will need to use the whitelist rather than the blacklist provided by the HTML cleaner. Not only in the case of the wrong context, even htmlspecialchars($var,ENT_QUOTES); it will not help you, since there are many ways to avoid using both html tags and quotes (stringFromChar using a backslash), you also need to consider various browser encodings, which this attack in UTF-7 \\\+ADw-script+AD4-alert(/xss/)+ADw-/script+AD4---//-- can allow for example \\\+ADw-script+AD4-alert(/xss/)+ADw-/script+AD4---//-- will be executed. Although HTMLPurifier does have a lot of overhead, it is a simple non-technical way to prevent XSS attacks (although there were, and I believe, holes will be in them too).
source share