In a very large project, it is difficult to find out which file is the document containing the BOM label, if we manually open each file to check, it will consume our large amount of time, and very troublesome, we can directly through the PHP program can easily find out the current project or directory of all the files , whether this BOM label is included.
The code is as follows:
";} Closedir ($DH);} function Checkbom ($filename) {global $auto; $contents =file_get_contents ($filename); $charset [1]=substr ($contents, 0, 1); $charset [2]=substr ($contents, 1, 1); $charset [3]=substr ($contents, 2, 1); if (Ord ($charset [1]) ==239 && Ord ($ CHARSET[2]) ==187 && ord ($charset [3]) ==191) {if ($auto ==1) {$rest =substr ($contents, 3); rewrite ($filename, $ rest); return ("BOM found, automatically removed.");} else {return ("BOM found.");}} else return ("BOM not Found.");} function rewrite ($filename, $data) {$filenum =fopen ($filename, "w"), Flock ($filenum, LOCK_EX); Fwrite ($filenum, $data); Fclose ($filenum);}
In fact, these code is also I find share on the Internet, because this period of time is busy, so there is no time to optimize the code, currently only check the current directory with the BOM label files, you can also add their own functions, such as
Automatically detects all files for subdirectories under the current project.
You can also select a file in a directory instead