为什么出现在我的HTML中?

时间:2012-03-13 20:40:38

标签: html

我在Firebug 中看到了这个角色。

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

我用utf-8编码保存了我的文件而没有bom。

enter image description here

10 个答案:

答案 0 :(得分:98)

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

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

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

答案 1 :(得分:77)

只需使用notepad ++编码UTF-8而无需BOM。

答案 2 :(得分:41)

是的,它很容易解决,只需通过记事本++打开该文件,然后按步骤操作 - >编码\编码没有BOM的UTF-8。 然后保存。 它对我也有用!

答案 3 :(得分:31)

尝试:

<?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

答案 4 :(得分:12)

“我不知道为什么会这样”

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

那将导致它!

答案 5 :(得分:8)

如果您使用的是Notepad ++,&#34;菜单&#34; &GT;&GT; &#34;编码&#34; &GT;&GT; &#34;转换为UTF-8&#34;你的&#34;包括&#34;文件。

答案 6 :(得分:6)

如果要查看大量文件,可以使用此工具: https://www.mannaz.at/codebase/utf-byte-order-mark-bom-remover/

致Maurice的信用

它帮助我清理系统,使用CakePhp中的MVC,因为我使用不同的工具在Linux,Windows中工作..在某些文件中我的设计是破坏的...所以在使用调试工具在Chrome中检查后找到&amp; #65279错误

答案 7 :(得分:3)

在清空(修剪)之前

然后用RegEx .replace("/\xEF\xBB\xBF/", "")

替换

我正在使用Javascript,我使用JavaScript。

答案 8 :(得分:0)

在这种情况下有效的旧愚蠢技巧......将编辑器中的代码粘贴到ms记事本中,然后反之亦然,邪恶的角色将会消失! 我从wyisyg / msword copypaste问题中获取灵感。 Notepad ++ utf-8 w / out BOM也适用。

答案 9 :(得分:0)

这是我的2美分: 我有同样的问题,我尝试使用Notepad ++转换为UTF-8无BOM,以及旧的“复制到MS记事本然后再回来”技巧,都无济于事。通过确保所有文件(和“包含的”文件)相同的文件系统来解决我的问题;我有一些Windows格式的文件和一些已经从远程Linux服务器复制的文件,因此是UNIX格式的。

相关问题