最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP 去掉 utf8格式文件中的bom头部
时间:2013-11-21 编辑:简简单单 来源:一聚教程网
例1
代码如下 | 复制代码 |
/** /** |
例2
如何将带有BOM文件的格式转换成无签名的UTF-8格式文件呢?下面分享给大家一段PHP代码:
代码如下 | 复制代码 |
//此文件用于快速测试UTF8编码的文件是不是加了BOM,并可自动移除 $basedir="."; //修改此行为需要检测的目录,点表示当前目录 //以下不用改动 if ($dh = opendir($basedir)) { function checkBOM ($filename) { function rewrite ($filename, $data) {
|
例3
代码如下 | 复制代码 |
$BOMBED = array(); RecursiveFolder($HOME); echo ' These files had UTF8 BOM, but i cleaned them:'; // 递归扫描 function RecursiveFolder($sHOME) { global $BOMBED, $WIN; $win32 = ($WIN == 1) ? "\" : "/"; $folder = dir($sHOME); $foundfolders = array(); while ($file = $folder->read()) { if($file != "." and $file != "..") { if(filetype($sHOME . $win32 . $file) == "dir"){ $foundfolders[count($foundfolders)] = $sHOME . $win32 . $file; } else { $content = file_get_contents($sHOME . $win32 . $file); $BOM = SearchBOM($content); if ($BOM) { $BOMBED[count($BOMBED)] = $sHOME . $win32 . $file; // 移出BOM信息 $content = substr($content,3); // 写回到原始文件 file_put_contents($sHOME . $win32 . $file, $content); } } } } $folder->close(); if(count($foundfolders) > 0) { foreach ($foundfolders as $folder) { RecursiveFolder($folder, $win32); } } } // 搜索当前文件是否有BOM function SearchBOM($string) { if(substr($string,0,3) == pack("CCC",0xef,0xbb,0xbf)) return true; return false; } ?> |
相关文章
- xampp怎么运行php文件 02-24
- php文件怎么打开?php文件打开教程 02-24
- php 格式种子文件怎么打开 02-23
- php怎么打开exe文件 php文件中如何调用在服务器上的exe文件 02-23
- php文件怎么打开 如何执行php文件 02-22
- php格式怎么打开?php格式种子文件怎么打开 02-22