156

I see this character in Firebug .

I don't know why this is happening, there's no such character in my code. For Firefox it's OK, but in IE everything breaks. I can't even search for this character in Google.

I saved my file with utf-8 encoding without bom.

enter image description here

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
mehdi
  • 9,262
  • 11
  • 35
  • 35
  • 6
    no it's NOT possible duplicate read this line of that post :"Encode in UTF-8 without BOM", and this seems to fix the problem. then read mine !! – mehdi Mar 13 '12 at 20:58
  • 1
    Two different symptoms of the same problem deserve to be enshrined in two different questions, IMO. Thanks mehdi for the screenshot of the Firebug symptom. Thanks @Vega for the link to the ajax symptom. – Bob Stein Mar 28 '13 at 20:16
  • 2
    If anyone is facing this problem in ASP.NET MVC with razor as view engine, then open your file in Notepad++ and check @using on top of the page. It will help you to figure out the issue. – Jivan Jun 15 '15 at 04:53
  • 1
    I am also getting this problem in my MVC6 web application. I have added below line in my layout page on very top & problem is resolved. – Optimus Jun 01 '16 at 19:21
  • 1
    Key answer ... keep your development files on ANSI/ASCII encoding – Ahmed Nabil Dec 13 '16 at 12:07
  • If you are in ASP.Net MVC - check whether you accidentally added a line on the very first line of your view file. – Binu Nov 02 '18 at 17:25

10 Answers10

120

The character in question &#65279 is the Unicode Character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF). It may be that you copied it into your code via a copy/paste without realizing it. The fact that it's not visible makes it hard to tell if you're using an editor that displays actual unicode characters.

One option is to open the file in a very basic text editor that doesn't understand unicode, or one that understands it but has the ability to display any non-ascii characters using their actual codes.

Once you locate it, you can delete the small block of text around it and retype that text manually.

RHSeeger
  • 16,034
  • 7
  • 51
  • 41
  • 21
    Go-go `notepad.exe`! Not much else it's good for. :D – kitti Mar 13 '12 at 20:46
  • 1
    I use emacs for such things, personally... but speaking to an audience with whom you're unsure of their familiarity with such tools, I figured it was best not to mention it :) – RHSeeger Mar 13 '12 at 20:49
  • i open it with notepad no unusual character was there and i save it now i have three character at the top . hooray ! :) – mehdi Mar 13 '12 at 20:56
  • This worked for me... i found the end was in a different sized font which was causing the issue. Thanks for this – Gerico Jun 10 '12 at 09:20
  • @Fred-ii- I'm not the OP ! – Gerico Jun 08 '15 at 16:24
  • @Mat-visual Oops, my mistake lol - I will retag my comment to the OP. I saw your comment *"This worked for me... i found the end was in a different sized font which was causing the issue. Thanks for this"* and thought it was you. – Funk Forty Niner Jun 08 '15 at 16:26
  • 1
    Salam. Also convert **Included file** to "UTF-8 without BOM" with notepad ++ – Sayed Abolfazl Fatemi Sep 09 '15 at 14:48
  • Key answer .. convert development files to "ANSI" with notepad ++ – Ahmed Nabil Dec 13 '16 at 12:08
  • I had to put in ini_set('memory_limit', '2G'); to make the script run. Also I made it into a command line script since my web user is unable to edit files. See https://gist.github.com/rlorenzo/13b4e58fc7cc47ca457a54ca8ab90c29 – rlorenzo Feb 21 '20 at 01:50
92

Just use notepad ++ with encoding UTF-8 without BOM.

shonhloi
  • 921
  • 5
  • 2
  • This works. The Facebook Object Debugger --> Scraped URL showed me that i had  breaking my header. – Ryan H Jun 26 '14 at 14:29
  • @shonhloi This worked much better and easier than RHSeeger's answer – Omar Apr 28 '16 at 06:33
  • 2
    Thank You. I setted in Menu: Encoding >> Encode in UTF-8. And it worked to me. Thanks. – Thiago Jul 03 '17 at 13:15
  • 1
    Just want to chime in - this works with Sublime Text, just open the offending file and choose "Save with Encoding" from the File menu and choose UTF-8. – Emanuele Ciriachi Oct 20 '17 at 12:34
45

yeah, its so simple to fix that, just open that file by notepad++ and step follow --> Encoding\ encoding UTF-8 without BOM. then save that. It work for me as well!

user1386086
  • 451
  • 3
  • 2
36

Try:

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

copy this code to php file upload to root and run it.

for more about this: http://forum.virtuemart.net/index.php?topic=98700.0

Pedram
  • 15,766
  • 10
  • 44
  • 73
Osama Elhamahmy
  • 360
  • 2
  • 4
14

"I don't know why this is happening"

Well I have just run into a possible cause:-) Your HTML page is being assembled from separate files. Perhaps you have files which only contain the body or banner portion of your final page. Those files contain a BOM (0xFEFF) marker. Then as part of the merge process you are running HTML tidy or xmllint over the final merged HTML file.

That will cause it!

ferg
  • 196
  • 1
  • 11
  • This also applies when using **Server Side Includes**: If the included files are stored with BOM (e.g. UTF-8 with Byte Order Mark), there will be appearances of `` in the file assembled by the webserver. Simple solution: Save the files as UTF-8 **without** Byte Order Mark. – The Conspiracy Apr 15 '16 at 22:45
  • Thank you so much, man. You have no idea how you saved my life. I had exactly the same problem. But it's NOT ALWAYS THAT EASY BECAUSE : . YEAH IT'S EASY WITH NOTEPAD++ BUT JUST LIKE YOU SAY WHEN THE WEBPAGE IS MADE WITH DIFFERENT INCLUDES, IT'S A PAIN TO FIND THE CULPRIT! . I FINALLY FOUND IT! . HALLELUJAH!!! . . – georgesjeandenis Jan 15 '19 at 09:05
11

If you are using Notepad++, "Menu" >> "Encoding" >> "Convert to UTF-8" your "include" files.

JohnA10
  • 326
  • 1
  • 4
  • 18
8

If you have a lot of files to review, you can use this tool: https://www.mannaz.at/codebase/utf-byte-order-mark-bom-remover/

Credits to Maurice

It help me to clean a system, with MVC in CakePhp, as i work in Linux, Windows, with different tools.. in some files my design was break.. so after checkin in Chrome with debug tool find the &#65279 error

5

Before clear space (trim)

Then replace with RegEx .replace("/\xEF\xBB\xBF/", "")

I'm working on Javascript, I did with JavaScript.

Robert
  • 5,278
  • 43
  • 65
  • 115
Oğuzhan Sari
  • 89
  • 1
  • 9
1

An old stupid trick that works in this case... paste code from your editor to ms notepad, then viceversa, and evil character will disappears ! I take inspiration from wyisyg/msword copypaste problem. Notepad++ utf-8 w/out BOM works as well.

Marcello
  • 21
  • 1
0

Here's my 2 cents: I had the same problem and I tried using Notepad++ to convert to UTF-8 no BOM, and also the old "copy to MS notepad then back again" trick, all to no avail. My problem was solved by making sure all files (and 'included' files) were the same file system; I had some files that were Windows format and some that had been copied off a remote Linux server, so were in UNIX format.

kurdtpage
  • 3,142
  • 1
  • 24
  • 24