php 去除bom 类
2015-12-13 10:25
549 查看
<?php /** * Created by JetBrains PhpStorm. * User: 张华 * Date: 14-3-8 * Time: 下午12:21 * QQ: 746502560@qq.com * To change this template use File | Settings | File Templates. */ $auto = 1; function instance($dir){ $basedir=isset($dir)?$dir:'.'; checkdir($basedir); } 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); $contents = preg_replace( '/^(\xef\xbb\xbf)/', '', $contents ); $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 ("<span style='color: #ff0000;'>找到bom错误,框架已自动删除.</span>"); } else { return ("<span style='color: #ff0000;'>找到了一个bom 错误,请你更改.</span>"); } } else return ("没有找到bom错误."); } function rewrite ($filename, $data) { $filenum = fopen($filename, "w"); flock($filenum, LOCK_EX); fwrite($filenum, $data); fclose($filenum); } ?>
相关文章推荐
- zhphp framework (二十八) token 加密与解密
- zhphpframework (二十七) php封装js函数
- zhphpframework(二十六) php+mysql 分页类
- php 算取两个时间的所有月份
- zhphp framework (二十四) 图片类 image
- zhphp framework (二十三) 文件缓存
- zhphp framewrok (二十二) file cache 文件缓存类
- zhphp framework(二十一) file 文件类
- php实现mysql备份
- zhphpframework (二十)cookie类
- php验证码类
- php日期类
- phpunit测试学习 2 分类总结断言涉及哪些方面
- phpunit测试学习 1:一点简单的扼要有用的东西的总结 一点入门认识
- phpunit测试成功 phpunit测试实践代码
- 3分钟wamp中php安装 pear 然而并没有用 并没能借此安装phpunit 不得不借用了其他的方式安装phpunit
- 5分钟windows wamp php安装phpunit 2015最新安装实践
- php--关于函数(2)变量范围
- RESTFUL及Yii框架下开发RESTFUL的细节
- 2015-oschina开源盛会,关于鸟哥分享的php7的会议纪要