Page 1 of 1

Stripping whitespace

Posted: Thu Nov 06, 2008 6:10 am
by alex.barylski
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.

Re: Stripping whitespace

Posted: Thu Nov 06, 2008 8:21 am
by JAB Creations
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.

Re: Stripping whitespace

Posted: Thu Nov 06, 2008 2:46 pm
by alex.barylski
1.) With over 4K posts there just isn't any excuse for posting code threads in the General Discussion forum. Ca'mon man.
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. :P

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. :P

I'll look into that link you provided.

Re: Stripping whitespace

Posted: Thu Nov 06, 2008 3:04 pm
by onion2k
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.