PHP批量去除BOM头代码分享
2015-06-26 00:00
645 查看
<?php /** * 去除bom头信息 */ header("Content-Type:text/html; charset=utf-8"); $auto = 1; checkdir("D:\wamp\www\sales"); function checkdir($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{ $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 ("<font color=red>发现BOM并且已自动删除</font>"); } else { return ("<font color=red>发现BOM</font>"); } } else return ("没有发现BOM"); } function rewrite ($filename, $data) { $filenum = fopen($filename, "w"); flock($filenum, LOCK_EX); fwrite($filenum, $data); fclose($filenum); } ?>
相关文章推荐
- 以文件形式缓存php变量的方法
- php通过获取头信息判断图片类型的方法
- PHP获取当前相对于域名目录的方法
- PHP中Session可能会引起并发问题
- php使用MySQL保存session会话的方法
- PHP实现事件机制实例分析
- PHP关联数组实现根据元素值删除元素的方法
- PHP empty()与isset()与is_null()的区别
- Yii2.0 中文手册
- 【php】【Laravel】【Route】跟我学Laravel之路由
- [php] 递归实现类目输出
- Windows下搭建PHP开发环境
- PHP学习笔记(五):isset和empty的区别
- PHP源码加密,以前只知道zend guard,今天才知道,原来还有个 ioncube
- PHP模拟链表_学习链表的一些操作
- php base64_decode 解码方法
- ubuntu下php不能显示中文的问题的解决过程。
- zend studio中ctrl+鼠标左键无法转到类或函数定义文件的解决方法
- PHP学习笔记(二):数据库连接
- PHP命名空间(Namespace)的使用详解