问题描述

我在 Firebug  中看到这个角色。

我不知道为什么会发生这种情况,在我的代码中没有这样的字符。对于 Firefox 来说没关系,但在 IE 中,一切都会中断。我甚至不能在 Google 搜索这个角色。

我保存我的文件与 utf-8 编码没有 bom 。

最佳解决方案

&#65279 中的字符是 Unicode 字符 “ZERO WIDTH NO-BREAK SPACE”(U + FEFF) 。这可能是您通过复制/粘贴将其复制到代码中,而无需实现。它不可见的事实很难判断您是否使用显示实际 unicode 字符的编辑器。

一个选项是在非常基本的文本编辑器中打开该文件,该文本编辑器不了解 unicode,或者可以理解它,但可以使用其实际代码显示任何 non-ascii 字符。

找到它后,您可以删除其周围的小块文本,并手动重新输入该文本。

次佳解决方案

只需使用不带 BOM 的 UTF-8 编码记事本。

第三种解决方案

是的,它很简单的解决方案,只是通过记事本++打开该文件,并跟随 – > 编码编码 UTF-8 没有 BOM 。然后保存。它也适用于我!

第四种方案

<?php
// Tell me the root folder path.
// You can also try this one
// $HOME = $_SERVER["DOCUMENT_ROOT"];
// Or this
// dirname(__FILE__)
$HOME = dirname(__FILE__);

// Is this a Windows host ? If it is, change this line to $WIN = 1;
$WIN = 0;

// That's all I need
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UTF8 BOM FINDER and REMOVER</title>
<style>
body { font-size: 10px; font-family: Arial, Helvetica, sans-serif; background: #FFF; color: #000; }
.FOUND { color: #F30; font-size: 14px; font-weight: bold; }
</style>
</head>
<body>
<?php
$BOMBED = array();
RecursiveFolder($HOME);
echo '<h2>These files had UTF8 BOM, but i cleaned them:</h2><p class="FOUND">';
foreach ($BOMBED as $utf) { echo $utf ."<br />n"; }
echo '</p>';

// Recursive finder
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;

          // Remove first three chars from the file
          $content = substr($content,3);
          // Write to file
          file_put_contents($sHOME . $win32 . $file, $content);
        }
      }
    }
  }
  $folder->close();

  if(count($foundfolders) > 0) {
    foreach ($foundfolders as $folder) {
      RecursiveFolder($folder, $win32);
    }
  }
}

// Searching for BOM in files
function SearchBOM($string) {
    if(substr($string,0,3) == pack("CCC",0xef,0xbb,0xbf)) return true;
    return false;
}
?>
</body>
</html>

将此代码复制到 php 文件上传到 root 并运行它。

更多关于这个:http://forum.virtuemart.net/index.php?topic=98700.0

第五种方案

“我不知道为什么会发生这种情况”

我刚刚遇到一个可能的原因:-) 您的 HTML 页面正在从单独的文件汇编。也许你有只包含最后一页的正文或横幅部分的文件。这些文件包含 BOM(0xFEFF) 标记。然后作为合并过程的一部分,您将在最终合并的 HTML 文件中运行 HTML tidy 或 xmllint 。

那会造成的!

第六种方案

如果您使用的是 Notepad ++,”Menu”>> “Encoding”>> “转换为 UTF-8” 您的”include” 文件。

第七种方案

如果您有很多文件要检查,可以使用以下工具:https://www.mannaz.at/codebase/utf-byte-order-mark-bom-remover/

对莫里斯的信用

它帮助我清理一个系统,在 CakePHP 中使用 MVC,因为我在 Linux,Windows 中使用不同的工具工作。在某些文件中,我的设计被打破了.. 所以在 Chrome 调试工具中检入&#65279 错误之后

参考文献

注:本文内容整合自 Google/Baidu/Bing 辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:薇晓朵技术论坛