Skip to content

Instantly share code, notes, and snippets.

@hirbod
Forked from jdlx/bom_check.php
Created May 11, 2012 15:47
Show Gist options
  • Save hirbod/2660552 to your computer and use it in GitHub Desktop.
Save hirbod/2660552 to your computer and use it in GitHub Desktop.
PHP script to recursively check php files for BOM (ByteOrderMark)
<?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