In an effort to reduce bandwidth, I am trying to strip out unnecessary whitespace. By "unnecessary", I am referring to any vertical whitespace, and horizontal whitespace at the start or end of lines, but not if it is in a <textarea>
tag.
While I am no stranger to The Pony He Comes, I'm fairly sure a full HTML parser would be overkill for this task. By my understanding, a regex could work.
The regex I have right now is:
$out = preg_replace("/[ \t]*\r?\n[ \t]*/","",$in);
This seems to strip out the whitespace I specify above, except for the <textarea>
rule. My question boils down to: How can I make sure that replacements do not happen within specified boundaries? It can be safely assumed that all HTML entities are properly escaped inside <textarea>
s.