<?php
// 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());
}
?>
转载于:https://my.oschina.net/u/151223/blog/351770