function trimbom_recursion($path) { $flag = FilesystemIterator::SKIP_DOTS | FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO; $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, $flag), RecursiveIteratorIterator::CHILD_FIRST); foreach ($objects as $value) { $realpath = $value->getRealpath(); $value->isFile() ? var_dump(checkBOM($value)) : true; } }
public function saveFile($path, $conent) { $path = $this->baseDir() . $path; $path = $this->trimPath($path); $isBOM = checkBOM($path); if ($isBOM) { writeUTF8WithBOMFile($path, $conent); return true; } else { return file_put_contents($path, $conent); } return false; }
function checkdir($basedir) { if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { if (!is_dir($basedir . "/" . $file)) { echo "filename: {$basedir}/\r\n\r\n{$file} " . checkBOM("{$basedir}/{$file}") . " <br>"; } else { $dirname = $basedir . "/" . $file; checkdir($dirname); } } } closedir($dh); } }
function checkdir($basedir) { if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { if (!is_dir($basedir . '/' . $file)) { $filename = $basedir . '/' . $file; echo 'filename:' . $basedir . '/' . $file . checkBOM($filename) . '<br>'; } else { $dirname = $basedir . '/' . $file; checkdir($dirname); } } } closedir($dh); } }
function checkdir($basedir) { if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..' && $file != '.svn') { if (!is_dir($basedir . "/" . $file)) { if (checkBOM("{$basedir}/{$file}") == 1) { echo "filename: {$basedir}/{$file} <font color=red>tồn tại, đã tự động xóa.</font> <br>"; } } else { $dirname = $basedir . "/" . $file; checkdir($dirname); } } } closedir($dh); } }
function checkdir($basedir) { if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { if (!is_dir($basedir . "/" . $file)) { if (checkBOM("{$basedir}/{$file}") == 1) { echo "filename: {$basedir}/{$file}<font color=red>found bom and remove!</font><br>"; } } else { $dirname = $basedir . "/" . $file; checkdir($dirname); } } } closedir($dh); } }
function checkdir($basedir) { if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..' && $file != '.svn') { if (!is_dir($basedir . "/" . $file)) { $res = checkBOM("{$basedir}/{$file}"); if ($res != 'BOM Not Found.') { echo "filename: {$basedir}/{$file} " . $res . " <br>"; } } else { $dirname = $basedir . "/" . $file; checkdir($dirname); } } } closedir($dh); } }
function checkdir($basedir = '', $loop = true) { $basedir = empty($basedir) ? '.' : $basedir; if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { if (!is_dir($basedir . '/' . $file)) { echo '文件: ' . $basedir . '/' . $file . checkBOM($basedir . '/' . $file) . ' <br>'; } else { if (!$loop) { continue; } $dirname = $basedir . '/' . $file; checkdir($dirname); } } } closedir($dh); } }
/** * 执行备份文件的SQL语句 * * @param string $filename */ function bakindata($filename) { $DB = Database::getInstance(); $setchar = $DB->getMysqlVersion() > '4.1' ? "ALTER DATABASE `" . DB_NAME . "` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;" : ''; $sql = file($filename); if (isset($sql[0]) && !empty($sql[0]) && checkBOM($sql[0])) { $sql[0] = substr($sql[0], 3); } array_unshift($sql, $setchar); $query = ''; foreach ($sql as $value) { $value = trim($value); if (!$value || $value[0] == '#') { continue; } if (preg_match("/\\;\$/i", $value)) { $query .= $value; if (preg_match("/^CREATE/i", $query)) { $query = preg_replace("/\\DEFAULT CHARSET=([a-z0-9]+)/is", '', $query); } $DB->query($query); $query = ''; } else { $query .= $value; } } }
//修改此行为需要检测的目录,点表示当前目录 if (isset($_GET['dir'])) { $basedir = $_GET['dir']; } else { $basedir = "."; } //是否自动移除发现的BOM信息。1为是,0为否。 if (isset($_GET['auto'])) { $auto = 0; } else { $auto = 1; } if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..' && !is_dir($basedir . "/" . $file)) { echo "filename: {$file} " . checkBOM("{$basedir}/{$file}") . " <br>"; } if ($file != '.' && $file != '..' && is_dir($basedir . "/" . $file)) { echo "<a href='?dir=" . $basedir . "/" . $file . "'>" . $basedir . "/" . $file . "</a><br>"; } } 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) {
function checkdir($basedir) { static $num = 0; if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..') { if (!is_dir($basedir . "/" . $file)) { if (file_ext($file) == 'php' && checkBOM("{$basedir}/{$file}", false)) { echo "filename: {$basedir}/{$file} <b style='color:red'>bom found.</b><br/>"; $num++; } } else { $dirname = $basedir . "/" . $file; checkdir($dirname); } } } closedir($dh); } return $num; }