How to Avoid Echoing Character 65279 in PHP

How to avoid echoing character 65279 in php?

To conclude, and specify the solution:

Windows Notepad adds the BOM character (the 3 bytes: EF BB BF) to files saved with utf-8 encoding.

PHP doesn't seem to be bothered by it - unless you include one php file into another -
then things get messy and strings gets displayed with character(65279) prepended to them.

You can edit the file with another text editor such as Notepad++ and use the encoding

"Encode in UTF-8 without BOM",

and this seems to fix the problem.

Also, you can save the other php file with ANSI encoding in notepad - and this also seem to work (that is, in case you actually don't use any extended characters in the file, I guess...)

PHP returns  html entity on print functions

This entity represents the BOM (Byte Order Mark, Unicode name "ZERO WIDTH NO-BREAK SPACE"). However,

  1. it should be at the very beginning of the file;
  2. it shouldn't be escaped as an HTML entity, but written as a plain character.

So something is clearly going wrong when encoding your file.

The character sequence "" is what the BOM looks like when it is encoded with UTF-8, but erroneously interpreted as Latin-1.

This might help you understand the problem.
In order to help you fix this, you need to provide more details/context on what exactly you are doing. For example, where/how do specify the encoding of the output file?

PHP Include function outputting unknown char

What you are seeing is a UTF-8 Byte Order Mark:

The UTF-8 representation of the BOM is the byte sequence EF BB BF, which appears as the ISO-8859-1 characters  in most text editors and web browsers not prepared to handle UTF-8.

Byte Order Mark on Wikipedia

PHP does not understand that these characters should be "hidden" and sends these to the browser as if they were normal characters. To get rid of them you will need to open the file using a "proper" text editor that will allow you to save the file as UTF-8 without the leading BOM.

You can read more about this problem here

PHP include() creates unwanted gaps in HTML

As Per Why is  appearing in my HTML?

it may have a Simple Fix!

The character in question  is the Unicode Character 'ZERO WIDTH
NO-BREAK SPACE' (U+FEFF) attached to your code on a copy/paste or during a faulty Save
its so simple to fix that,
just open that file by notepad++ and step follow -->
Encoding->Encode in UTF-8 without BOM. then save that. It work for me as well!

Where is the data coming from?

Everything not inside your <?php ... ?> tags is treated as text and sent to the client. So make sure not to have empty lines in your source files...

Edit: The purpose of this is to have a simple way to have a HTML file mixed with portions of PHP code without the need to echo all the HTML stuff explicitly...

json_encode creating a malformed JSON (with extra hidden character)

It could be an issue with a BOM mark. Try to save the file as normal UTF-8 instead.



Related Topics



Leave a reply



Submit