問題描述

我在 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 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇