PDA

View Full Version : ..A Program To Remove Blank Spaces


Doug E
2007-03-28, 12:39 AM
Im looking for a program that removes all blank spaces from my code. Ive tried numerous searches but cant figure out how to word it exactly.

I want to turn this...


<html>

<head>
<title></title>
</head>
<body>

</body>
</html>




..into this...

<html><head><title></title></head><body></body></html>


...with the click of the button

MightyMidget
2007-03-28, 07:08 AM
Dunno, but if you can't find one I could always code the program for you. Won't take long and wouldn't cost much.

Why do you need that functionality anyway?

Lemmy
2007-03-28, 07:34 AM
Dreamweaver will do that for you. Just create an empty line in code view, highlight it and do a find and replace. Leave the replace field empty. Voila!

Greenguy
2007-03-28, 10:27 AM
Namo (http://www.namo.com/) has a handy little html clean up option that makes the source code look nice & tidy.

MightyMidget
2007-03-28, 11:03 AM
If I understood it correctly he also wants trailing and preceding spaces/tabs to be removed, so that code like


<html>
<body>
</body>
</html>


would also become


<html><body></body></html>


so a simple find/replace of newlines won't do. An editor that supports regular expressions would be able to do it, like UltraEdit, but if you want to do this on a lot of files then a command line utility would be better.

tickler
2007-03-28, 03:08 PM
Not sure why people would want these anymore. It is much preferable to keep the indents/newlines if you ever need to do work on the page(s).

Absolute HTML Compressor (http://www.download.com/Absolute-HTML-Compressor/3000-2068_4-10208022.html)

Doug E
2007-03-28, 08:57 PM
Not sure why people would want these anymore. It is much preferable to keep the indents/newlines if you ever need to do work on the page(s).

Its for a fussy script that doesn't like blank spaces between tags. Actually, 2 scripts, both unrelated so I assume there are more out there like this.

I ended up doing it all by hand last night with end delete end delete..., a very boring 1.5 hours.

Ill try those suggestions tonight and see which works for next time...

Whipple
2007-04-02, 02:25 AM
Theres several ways you can do this, but I would just write a quick php script to spit out the html in a line and copy / paste it (If you wanted to have the script actually write to the file you could, but it's not that hard to copy paste ;))


<?php

$file = file_get_contents("html.html");
echo htmlentities($file);

?>


Just quick explanation.. file_get_contents() (http://www.php.net/file_get_contents) grabs all of the text in "html.html" file into a string (all in one line), next line just spits it out in the format you want. If you want something more elaborate you can look into the following functions:

str_replace() (http://www.php.net/str_replace)
fopen() (http://www.php.net/fopen)
fread() (http://www.php.net/fread)

oast
2007-04-03, 05:14 AM
I use UltraEdit's "replace text in files" option.
It can do multiple files and will remove all tabs, new lines and spaces between tags in three passes, with the option to do a "test" run to make sure your search line is correct before commiting to every file.