检测文件是否有bom头 - PHP
2013-09-23 08:18
176 查看
<? //此文件用于快速测试UTF8编码的文件是不是加了BOM,并可自动移除 //By Bob Shen $basedir="."; //修改此行为需要检测的目录,点表示当前目录 $auto=1; //是否自动移除发现的BOM信息。1为是,0为否。 //以下不用改动 if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file!='.' && $file!='..' && !is_dir($basedir."/".$file)) echo "filename: $file ".checkBOM("$basedir/$file")." <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) { if ($auto==1) { $rest=substr($contents, 3); rewrite ($filename, $rest); return ("<font color=red>BOM found, automatically removed.</font>"); } else { return ("<font color=red>BOM found.</font>"); } } else return ("BOM Not Found."); } function rewrite ($filename, $data) { $filenum=fopen($filename,"w"); flock($filenum,LOCK_EX); fwrite($filenum,$data); fclose($filenum); }
相关文章推荐
- 检测文件是否有bom头 - PHP
- ubuntu php.ini文件位置,检测php环境是否ok
- 原来php的dirname不检测文件是否存在
- php安全的改进以及检测文件是否被篡改
- php 检测文件是否存在的几种方式
- PHP中检测文件是否为UTF-8编码的函数
- PHP批量检测并去除文件BOM头代码实例
- PHP检测文件方法,类方法是否存在
- [置顶] PHP批量检测并去除文件BOM头代码实例 导致空白行解决办法
- 检测php文件是否有bom头
- PHP检测远端文件是否存在
- PHP批量检测并去除文件BOM头代码实例
- 检测文件是否有BOM头并去除BOM头
- 检测文件是否存在脚本
- php method_exists 检测类中是否包括函数
- php 判断文件或目录是否存在
- [置顶] php检测输入数据是否合法常用的类
- 检查目录下php文件是否含有bom
- PHP判断文件是否被引入的方法get_included_files
- php被包含文件中的变量是否可在包含它的脚本中直接使用