Last active
November 30, 2018 01:55
-
-
Save timint/509b5f845144478c9ba51763e0f217cf to your computer and use it in GitHub Desktop.
A script to find all PHP files with leading or trailing whitespace
This file contains hidden or 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 | |
header('Content-Type: text/plain'); | |
$dir_iterator = new RecursiveDirectoryIterator("./"); | |
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); | |
$count=0; | |
foreach ($iterator as $file) { | |
$count++; | |
if (!preg_match('#\.php$#', $file)) continue; | |
$contents = file_get_contents($file); | |
if (preg_match('#^\s+<\?php#', $contents)) { | |
echo $file .' (Whitespace before opening <?php at BOF)'. PHP_EOL; | |
} | |
if (preg_match('#\?>\s+$#', $contents)) { | |
echo $file .' (Whitespace after closing ?> at EOF)'. PHP_EOL; | |
} | |
} | |
echo "$count files scanned" . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment