-
-
Save R0B3RDV/70092dfcee0286c38442466c7c16f4ca 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 | |
* @see http://www.dotvoid.com/2010/04/detecting-utf-bom-byte-order-mark/ | |
* @version 1.1 | |
*/ | |
// SETTINGS | |
//////////////////////////////////////////////////////////////////////////////// | |
$check_extensions = array('php'); | |
// MAIN | |
//////////////////////////////////////////////////////////////////////////////// | |
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']) && in_array($path_parts['extension'],$check_extensions)) | |
{ | |
$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