Advertisement
Guest User

Detect BOM sequence in a folder recursively

a guest
May 4th, 2010
1,170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. define('STR_BOM', "\xEF\xBB\xBF");
  4. $file = null;
  5. $directory = getcwd();
  6.  
  7. $rit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory), RecursiveIteratorIterator::CHILD_FIRST);
  8. try {
  9.     foreach ($rit as $file) {
  10.         if ($file->isFile()) {
  11.             $path_parts = pathinfo($file->getRealPath());
  12.  
  13.             if ('php' == $path_parts['extension']) {
  14.                 $object = new SplFileObject($file->getRealPath());
  15.  
  16.                 if (false !== strpos($object->getCurrentLine(), STR_BOM)) {
  17.                     print $file->getRealPath()."\n";
  18.                 }
  19.             }
  20.         }
  21.     }
  22.  
  23. } catch (Exception $e) {
  24.     die ('Exception caught: '. $e->getMessage());
  25. }
  26.  
  27. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement