Stripping whitespace

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Stripping whitespace

Post 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.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Stripping whitespace

Post 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.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Stripping whitespace

Post 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.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Stripping whitespace

Post 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.
Post Reply