utf-8(不含BOM头)
从上图的比较中,可以很明显的看出,含BOM头的文件多出三个字节 efbbbf。
3. BOM头信息的去除方法
用Notepad++打开文件,选择 格式 -> 以UTF-8无BOM格式编码,再保存就行。如下图:
4. 在PHP类的项目中,自动处理BOM头信息(只需要将此文件放在项目根目录下,从浏览器访问即可)
<</font>?php
if (isset($_GET['dir'])) { //设置文件目录
$basedir = $_GET['dir'];
} else {
$basedir = '.';
}
checkdir($basedir);
function checkdir($basedir) {
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..') {
if (!is_dir($basedir . "/" . $file)) {
echo "filename: $basedir/$file " . checkBOM("$basedir/$file") . "
";
} else {
$dirname = $basedir . "/" . $file;
checkdir($dirname);
}
}
}
closedir($dh);
}
}
function checkBOM($filename, $auto = 1) {
$contents = file_get_contents($filename);
$charset[1] = substr($contents, 0, 1);
$charset[2] = substr($contents, 1, 1);
$charset[3] = substr($contents, 2, 1);
|
版权声明: 本站资源均来自互联网或会员发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!
转载请注明: UTF-8文件的BOM头的来由及去除方法