0

I am having trouble with a script that's echoing some simple text.

It should output:

M9785000 
PRE4371

But it actually outputs

M9785000 
PRE4371

The response headers are:

Accept-Ranges   bytes
Connection  close
Content-Type    text/html
Date    Tue, 28 May 2013 08:15:48 GMT
Server  Apache
X-Powered-By    PHP/5.2.17

It was chunked before but I downgraded the output so its not chunked but this doesn't help for a clean output of the echoed chars.

What could be the issue and how could I resolve it?

hakre
  • 193,403
  • 52
  • 435
  • 836
Cy.
  • 2,125
  • 4
  • 26
  • 35
  • Your browser doesn't understand encoding. Therefore, it's crap. – Cole Tobin Jun 23 '13 at 06:43
  • 1
    @Cole Johnson: [Default charset of text/html](http://tools.ietf.org/html/rfc1866#section-6.1) is Latin-1/CP-1252, therefore the browser perfectly well understands the encoding and is not crap. The HTML 5 living standard honors this by the way, and it's far away from shortening it to the crap-formula, see [this answer specific to HTML 5](http://stackoverflow.com/a/11820099/367456) and keep in mind that HTML 5 "hijacked" the text/html content type (redefining Latin-1 to CP-1252 for compability reasons, should not introduce too many problems). – hakre Jun 23 '13 at 09:48

2 Answers2

3

Your issue is Byto Order Mark (BOM)

read more about it here: http://www.w3.org/International/questions/qa-byte-order-mark.en.php

This could be a duplicate of: How do I remove  from the beginning of a file?

Community
  • 1
  • 1
Francis Yaconiello
  • 10,829
  • 2
  • 35
  • 54
  • Also, your response headers seem to be missing `charset`. http://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Responses something like: `Content-Type: text/html; charset=utf-8` BOM is used in UTF8 so make sure you are setting the charset that is returned appropriately. – Francis Yaconiello Jun 02 '13 at 23:06
1

You have a Byte Order Mark (BOM) character in your file. It is used in UTF-8 encoding, which causes  to show up when converted to ISO-8859-1 encoding.

If you have notepad++, you can use the inbuilt option. Go to Menu > Encoding > Convert to UTF-8 wihtout BOM. It is a great editor, I use this.

If you prefer vim, you can do this :

vim file
:set nobomb
:wq
user568109
  • 47,225
  • 17
  • 99
  • 123
  • My file is a .php file that generates the outputs using echo commands. Do you think that this solution would work? – Cy. Jun 02 '13 at 17:42
  • First identify the source of the BOM character. May be it is the file, maybe it is the output of commands. – user568109 Jun 02 '13 at 17:46