Created
May 11, 2012 15:39
-
-
Save jdlx/2660507 to your computer and use it in GitHub Desktop.
PHP script to recursively check php files for BOM (ByteOrderMark)
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 | |
/** | |
* @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()); | |
} | |
?> |
when run it it just says BOM Check
2021 and still works like a charm. Thanks for sharing - danke :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Danke Jan, hat mir soeben ein paar graue Haare erspart :)