Skip to content

Instantly share code, notes, and snippets.

@fzaninotto
Created April 6, 2011 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fzaninotto/906324 to your computer and use it in GitHub Desktop.
Save fzaninotto/906324 to your computer and use it in GitHub Desktop.
Remove trailing spaces from PHP source files
<?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