Home  >  Article  >  Backend Development  >  PHP method to remove BOM headers from project files in batches

PHP method to remove BOM headers from project files in batches

不言
不言Original
2018-07-04 14:21:161582browse

This article mainly introduces the method of removing BOM headers from project files in batches in PHP. It has certain reference value. Now I share it with you. Friends in need can refer to it.

 1 ";
 18                 } else {
 19                     $dirname = $basedir . "/" . $file;
 20                     checkdir($dirname);
 21                 }
 22             }
 23         }
 24         closedir($dh);
 25     }
 26 }
 27 
 28 function checkBOM($filename)
 29 {
 30     global $auto;
 31     $contents = file_get_contents($filename);
 32     $charset[1] = substr($contents, 0, 1);
 33     $charset[2] = substr($contents, 1, 1);
 34     $charset[3] = substr($contents, 2, 1);
 35     if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
 36         if ($auto == 1) {
 37             $rest = substr($contents, 3);
 38             rewrite($filename, $rest);
 39             return ("BOM found, automatically removed.");
 40         } else {
 41             return ("BOM found.");
 42         }
 43     } else
 44         return ("BOM Not Found.");
 45 }
 46 
 47 function rewrite($filename, $data)
 48 {
 49     $filenum = fopen($filename, "w");
 50     flock($filenum, LOCK_EX);
 51     fwrite($filenum, $data);
 52     fclose($filenum);
 53 }
 54 
 55 ?>

The above is the entire article Content, I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to import data from PHP Excel to MySQL database

About the strtr function in PHP Explanation for some strange behavior

The above is the detailed content of PHP method to remove BOM headers from project files in batches. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn