Solved

HTML spacing

Posted on 2002-05-30
9
177 Views
Last Modified: 2010-03-05
I have an html document and I would like to remove all of the spaces (blank lines).  Theres only one catch I want the body tag spaces not to be touched. Leaving the spaces in between the paragraphs alone.

I.e.
<html>

<head>


<title> This is my Web page

</title>



<head>

<body>
The paragraphs in this script should not be touched.

I would like the spacing to be the same.

Can this be done.
</body>

</html>

Should look like this:

<html>
<head>
<title> This is my Web page
</title>
<head>
<body>
The paragraphs in this script should not be touched.

I would like the spacing to be the same.

Can this be done.
</body>
</html>
0
Comment
Question by:kennybud416
9 Comments
 
LVL 3

Expert Comment

by:tgoetze
ID: 7045715
$removing_on = 1;
while(<>) {
    $removing_on = 0 if (/\<body\>/);
    print unless ($removing_on && /^$/);
}
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 7045972
$_ = join'',<>;
s/\n\s*\n|(<body>.*?<\/body>)/${[$1,"\n"]}[!$1]/sgi;
print;
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7046151
what difference does it make?

all browsers ignore white spaces.
0
 
LVL 3

Expert Comment

by:tgoetze
ID: 7046337
ozo,

Very nice, now if you could just obfuscate it a little, maybe you could win a contest. :)

Matching section seems straightforward enough. Is that an array of hashes in the replacement section?
If so, when does it get built?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:lexxwern
ID: 7046343
RE:
what difference does it make?
all browsers ignore white spaces.
0
 
LVL 3

Expert Comment

by:tgoetze
ID: 7046347
lexxwern,

Maybe it is not being viewed in a browser.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7046399
could be, but i'ld want kennybud416 to answer this question.
0
 
LVL 8

Expert Comment

by:bebonham
ID: 7047248
actually one time I read a book that reccomended removing all white space to ...get this...

decrease the time to load page.

ha ha.

yeah, this is true, it does have a good effect, but ...well, it's way to anal for me.

0
 

Author Comment

by:kennybud416
ID: 7051561
The xml file runs through a perl script.  This perl scirpt put each field(tag) into the orcale database. Each tag is assigned a certain number of chacters in the database.  if there are too many spaces in between two tags the tags are rejected and thrown away.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now