Hi,
I've been trying to find a script that I can run in my www document root to strip all spaces/empty tabs from all *.php, *.html, *.js files.
It seems like something many before me would have wanted, but I couldn't find any, not one example.
So I'll headstart this myself, by using RegExp and perl one should be able to get that done, right?
Example input, file.php, with crap indenting dev tab and space:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Upgrading to Pivot 1.40: checking for changes..</title>
</head>
<body>
<h1>Upgrading to blabla for changes..</h1>
<p><em>Version 1.6</em></p>
<p>From blabla other things. </p>
<p>This simple script checks if you've made the required change backup it first. You never know when you might need it. </p>
<p><strong>Note:</strong> Make sure this file is in your <tt>pivot/</tt> folder. Otherwise it'll give incorrect results!</p>
<?php
if (!file_exists(dirname(__FILE__)."/pv_core.php")) {
die("<strong>This script should be placed in your Pivot directory.</strong>");
}
include_once("pvlib.php");
load_all_templates();
echo "<h2>Getting rid of miscellaneous old unused files/directories</h2>";
$filestocheck = array(
"./includes/calendar.php"
);
foreach ($filestocheck as $filetocheck) {
if (filepresent($filetocheck)) {
warn("The file <tt>$filetocheck</tt> is still present. You should remove it.");
} else {
pass("The file <tt>$filetocheck</tt> is not present.");
}
}
Which should be replaced by:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>Upgrading to Pivot 1.40: checking for changes..</title></head><body><h1>Upgrading to blabla for changes..</h1>
<p><em>Version 1.6</em></p>
<p>From blabla other things. </p>
<p>This simple script checks if you've made the required change backup it first. You never know when you might need it. </p>
<p><strong>Note:</strong> Make sure this file is in your <tt>pivot/</tt> folder. Otherwise it'll give incorrect results!</p>
<?php
if (!file_exists(dirname(__FILE__)."/pv_core.php")) {
die("<strong>This script should be placed in your Pivot directory.</strong>");
}
include_once("pvlib.php");
load_all_templates();
echo "<h2>Getting rid of miscellaneous old unused files/directories</h2>";
$filestocheck = array(
"./includes/calendar.php"
);
foreach ($filestocheck as $filetocheck) {
if (filepresent($filetocheck)) {
warn("The file <tt>$filetocheck</tt> is still present. You should remove it.");
} else {
pass("The file <tt>$filetocheck</tt> is not present.");
}
}
It should
- remove all empty lines that are not enclosed as text
(so searching linebreak linebreak should replace as linebreak)
- trailing and indenting spaces should de removed
(so searching space|tab linebreak should replace as linebreak,
and linebreak space|tab should replace as just linebreak,
as well as all occurances of double spaces and/or tabs should disappear,
those never make sense in any html either way, except for when
enclosed with PRE/TT tag
Is there anybody out there that did this already? If so, let me know.
Would be great to have a script like this, to get rid of all that slack in production websites.