搜索
首页php教程PHP源码批量去除BOM头

跳至 [1] [全屏预览]
<?php
/**
 *去除所有文件BOM
 *author Caihong_tang
 *@created 2016-6-13 10:05:34
 */
if (isset($_GET['dir'])){
  $basedir=$_GET['dir']; 
}
else{ 
  $basedir = '.'; 
} 
$auto = 1; 
checkdir($basedir); 
function checkdir($basedir){ 
  if ($dh = opendir($basedir)) { 
    while (($file = readdir($dh)) !== false) { 
      if ($file != '.' && $file != '..'){ 
        if (!is_dir($basedir."/".$file)) { 
          echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." <br>"; 
        }
        else{ 
          $dirname = $basedir."/".$file; 
          checkdir($dirname); 
        } 
      } 
    } 
    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 ("<p color=red>BOM found, automatically removed.</p>"); 
    } 
    else { 
      return ("<p color=red>BOM found.</p>"); 
    } 
  } 
  else return ("<p>BOM Not Found.</p>"); 
} 
function rewrite ($filename, $data) { 
  $filenum = fopen($filename, "w"); 
  flock($filenum, LOCK_EX); 
  fwrite($filenum, $data); 
  fclose($filenum); 
} 
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
2 周前By尊渡假赌尊渡假赌尊渡假赌
仓库:如何复兴队友
4 周前By尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境