-
-
Save hirbod/2660552 to your computer and use it in GitHub Desktop.
PHP script to recursively check php files for BOM (ByteOrderMark)
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 | |
/** | |
* @author Atanas Vasilev | |
* @link http://pastebin.com/dHbqjUNy | |
*/ | |
define('STR_BOM', "\xEF\xBB\xBF"); | |
$file = null; | |
$directory = getcwd(); | |
$rit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST); | |
echo '<h1>BOM Check</h1>'; | |
try | |
{ | |
foreach ($rit as $file) | |
{ | |
if ($file->isFile()) | |
{ | |
$path_parts = pathinfo($file->getRealPath()); | |
if (isset($path_parts['extension']) && 'php' == $path_parts['extension']) | |
{ | |
$object = new SplFileObject($file->getRealPath()); | |
if (false !== strpos($object->getCurrentLine(), STR_BOM)) | |
{ | |
echo $file->getRealPath().'<br />'; | |
} | |
} | |
} | |
} | |
} | |
catch (Exception $e) | |
{ | |
die ('Exception caught: '. $e->getMessage()); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment