Stripping whitespace
Posted: Thu Nov 06, 2008 6:10 am
I have several HTML/PHP templates...the jQuery is tremendous with all the white space...
I want to strip the templates of all their non-essential whitespace but I wonder if something already exists? A function?
What whitespace is NOT to be removed:
1. Anything inside a string (single or double quote)
2. Anything inside an HTML tag <a href> obviously that whitespace is required
3. The single white space right after an PHP opening tag
EDIT | I guess 2 and 3 are somewhat connected or the same. White space in a TAG can be removed just not the first space immediately after the tag, same applies to PHP open tags.
Knowing I have PHP/CSS/HTML/JAVASCRIPT in the template file...what would be a safe algorithm to implement? Keep track of when I'm inside a TAG or STRING everything else is far game???
Hopefully you can spot something I missed as I need this to be rather bullet proof.
I want to strip the templates of all their non-essential whitespace but I wonder if something already exists? A function?
What whitespace is NOT to be removed:
1. Anything inside a string (single or double quote)
2. Anything inside an HTML tag <a href> obviously that whitespace is required
3. The single white space right after an PHP opening tag
EDIT | I guess 2 and 3 are somewhat connected or the same. White space in a TAG can be removed just not the first space immediately after the tag, same applies to PHP open tags.
Knowing I have PHP/CSS/HTML/JAVASCRIPT in the template file...what would be a safe algorithm to implement? Keep track of when I'm inside a TAG or STRING everything else is far game???
Hopefully you can spot something I missed as I need this to be rather bullet proof.