1.<?php
2.if (isset($_GET['dir'])){
3.
4.$basedir=$_GET['dir'];
5.}else{
6.$basedir = '.';
7.}
8.$auto = 1;
9.checkdir($basedir);
10.function checkdir($basedir){
11.if ($dh = opendir($basedir)) {
12.while (($file = readdir($dh)) !== false) {
13. if ($file != '.' && $file != '..'){
14. if (!is_dir($basedir."/".$file)) {
15. echo "filename: $basedir/$file ".checkBOM("$basedir/$file")."
";
16. }else{
17. $dirname = $basedir."/".$file;
18. checkdir($dirname);
19. }
20. }
21.}
22.closedir($dh);
23.}
24.}
25.function checkBOM ($filename) {
26.global $auto;
27.$contents = file_get_contents($filename);
28.$charset[1] = substr($contents, 0, 1);
29.$charset[2] = substr($contents, 1, 1);
30.$charset[3] = substr($contents, 2, 1);
31.if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) {
32.if ($auto == 1) {
33. $rest = substr($contents, 3);
34. rewrite ($filename, $rest);
35. return ("BOM found, automatically removed.");
36.} else {
37. return ("BOM found.");
38.}
39.}
40.else return ("BOM Not Found.");
41.}
42.function rewrite ($filename, $data) {
43.$filenum = fopen($filename, "w");
44.flock($filenum, LOCK_EX);
45.fwrite($filenum, $data);
46.fclose($filenum);
47.}
48.?>