1.     由于本人才疏学浅,对问题认知难免有偏差,本着学习与共享的精神和大家一起探讨,若有不对之处,望大家多多批评指正。
  2.  
  3. <?php 
  4. //author:马荣财 
  5. //EF BB BF这三个字节称为bom头    
  6. function hasbom(&$content) {   
  7.     $firstline = $content[0];   
  8.     return ord(substr($firstline, 0, 1)) === 0xEF   
  9.         and ord(substr($firstline, 1, 1)) === 0xBB    
  10.         and ord(substr($firstline, 2, 1)) === 0xBF;   
  11. }   
  12. function unsetbom(&$content) {   
  13.     hasbom($contentand ($content[0] = substr($content[0], 3)); 
  14.     echo '该文件有bom头标'
  15. }   
  16. function write($filename, &$content) {   
  17.     $file = fopen($filename'w');   
  18.     fwrite($file, implode($content''));   
  19.     fclose($file);   
  20. }   
  21. function filenames($path) {   
  22.     $directory = opendir($path);   
  23.     while (false != ($filename = readdir($directory))) strpos($filename'.') !== 0 and $filenames[] = $filename;   
  24.     closedir($directory);   
  25.     return $filenames;   
  26. }   
  27. function process($path) {   
  28.     $parent = opendir($path);   
  29.     while (false != ($filename = readdir($parent))) {   
  30.        echo $filename."/n";   
  31.         if(strpos($filename'.') === 0) continue;   
  32.         if(is_dir($path.DIRECTORY_SEPARATOR.$filename)) {   
  33.             process($path.DIRECTORY_SEPARATOR.$filename);   
  34.         } else {   
  35.             $content = file($path.DIRECTORY_SEPARATOR.$filename);   
  36.             unsetbom($content);   
  37.             write($path.DIRECTORY_SEPARATOR .$filename$content);   
  38.         }   
  39.     }   
  40.     closedir($parent);   
  41. }   
  42. process('/tmp/mrc');  
  43. ?>