Can you give us an example input string and what your desired output would be?
–
tptcatAug 19 '12 at 16:29

Imagine string full of tabs, spaces, new lines, and you'll get it. Now imagine some of them are html encoded, eg &nbsp; etc.
–
AnonymousAug 19 '12 at 16:30

I was thinking more of a real example. Not a description of an example. Show us a value of $var. You need to be specific about exactly which parts of the string you want to replce, not just "whitespaces and other garbage". The problem is you're question is too general to the point that if someone gives you an answer that might help, they'll likely be missing something you need to remove because you weren't specific enough.
–
tptcatAug 19 '12 at 16:34

I'm looking for the equivalent for the above regex, which is 100% valid, and removes the following characters: \s \t \n \r, and I want to expand it to match their encoded equivalents as well.
–
AnonymousAug 19 '12 at 16:36

Again, you really need to give an example of $var. Not doing so is making it difficult for you to get a good and thorough answer. I'm not sure why that is difficult. Good luck.
–
tptcatAug 19 '12 at 16:42

Note: technically 127 (ESC) is ascii too, but I skipped it for the sake of a shorter example.

You could either expand the callback (and the regex) or remove named entities in an intermediate step. However note that &nbsp; is not equivalent to &#32; but rather &#160; which is a space-width invisible character that may not wrap. Same goes for other named entities (you usually want to keep &shy;, &amp;, etc.)