Automatic condensing of whitespace in HTML One of the things that has occurred to me more recently is that if you add up all of the bandwidth that is taken up by thousands of users downloading the newlines and tabs used to make HTML source code readable... that's a LOT of wasted bandwidth.

So I wanted to add some code that would condense whitespace on-the-fly before sending it to the browser.

I then very quickly realised that sometimes, whitespace is significant. For example, in &lt;textarea&gt;s or &lt;pre&gt; tags.

After double-checking, I've come to the firm conclusion that there is absolutely no use of white-space CSS values such as pre-wrap that would make whitespace significant, except in the case of a custom &lt;rainbow&gt; tag (which is parsed by JavaScript for colour codes and things - long story XD)

So with that in mind, I wanted to condense whitespace that is not contained in a &lt;textarea&gt;, &lt;pre&gt; or &lt;rainbow&gt;. I accomplished this with DOMDocument and a DOMXPath, in other words, "doing it right". But then I learned about regex verbs, and replaced my code with this:

// uber hax with regex
$str = trim(preg_replace("(&lt;(textarea|rainbow|pre).*?&lt;/\\1&gt;(*SKIP)(*F)|\s+)s"," ",$str));


It, um... well, it works, or at least it seems to from what I can tell. But I wanted to post here so I can ask, have I missed anything important? Or is it really this simple?
I don't see much reason to use (*F) instead of the somewhat more understandable (*FAIL).
Consider using single-quoted (') strings for regular expressions to avoid \\1.
There's a big assumption here that the HTML will be well-formed. I assume (ha!) that this is okay.
Whitespace is significant in &lt;input&gt; tags.