Created
April 6, 2011 19:19
-
-
Save fzaninotto/906324 to your computer and use it in GitHub Desktop.
Remove trailing spaces from PHP source files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$tests=array(); | |
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__,0|\RecursiveDirectoryIterator::SKIP_DOTS)), '/\.php$/') as $file) { | |
if (strpos((string) $file, '.svn')) { | |
continue; | |
} | |
$tests[] = realpath((string) $file); | |
} | |
foreach ($tests as $file) { | |
$content = file_get_contents($file); | |
$content2 = preg_replace(array('/\;[ \t]+$/m', '/\{[ \t]+$/m', '/\)[ \t]+$/m'), array(';', '{', ')'), $content); | |
if ($content2 != $content) { | |
echo("$file\n"); | |
file_put_contents($file, $content2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment