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.
Stripping whitespace
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Stripping whitespace
Two things...
1.) With over 4K posts there just isn't any excuse for posting code threads in the General Discussion forum. Ca'mon man.
2.) This thread I started last night might have some good stuff for you to go by.
viewtopic.php?f=1&t=90427
If it's not then you might need to use regex though it's always the last resort method.
1.) With over 4K posts there just isn't any excuse for posting code threads in the General Discussion forum. Ca'mon man.
2.) This thread I started last night might have some good stuff for you to go by.
viewtopic.php?f=1&t=90427
If it's not then you might need to use regex though it's always the last resort method.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Stripping whitespace
This is always a touchy issue...while I agree it's annoying when questions are mis-appropriately located I think forum regulars should get a break.1.) With over 4K posts there just isn't any excuse for posting code threads in the General Discussion forum. Ca'mon man.
I mean...it's not really worthy of T & D...and it's not PHP specific nor is it related directly to programming, so...
General seemed appropriate.
I'll look into that link you provided.
Re: Stripping whitespace
I agree. It doesn't fit in T&D. So I've moved it to Misc, home of the "don't know where this goes" programming questions.