• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php 批量去除项目文件bom头的方法

php 搞代码 3年前 (2022-01-22) 15次浏览 已收录 0个评论

这篇文章主要介绍了关于php 批量去除项目文件bom头的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

 1 <?php  2 if (isset($_GET['dir'])) { //设置文件目录  3     $basedir = $_GET['dir'];  4 } else {  5     $basedir = '.';  6 }  7   8 $auto = 1;  9 checkdir($basedir); 10  11 function checkdir($basedir) 12 { 13     if ($dh = opendir($basedir)) { 14         while (($file = readdir($dh)) !== false) { 15             if ($file != '.' && $file != '..') { 16                 if (!is_dir($basedir . "/" . $file)) { 17                     echo "filename: $basedir/$file " . checkBOM("$basedir/$file") . " <br>"; 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 ("<font color='red'>BOM found, automatically removed.</font>"); 40         } else { 41             return ("<font color='red'>BOM found.</font>"); 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 ?>

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请随时关注我们网站!

相关推荐:

PHP Excel导入数据到MySQL数据库的方法

关于(本文来源gaodai#ma#com搞@@代~&码网

搞代gaodaima码

PHP中strtr函数一些奇怪行为的解释

以上就是php 批量去除项目文件bom头的方法的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 批量去除项目文件bom头的方法
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址