How to avoid echoing character 65279 in php? (This question also relates to Javascript xmlhttp.responseText (ajax)) -


i have encountered similar problem described here (and in other places) - on ajax callback xmlhttp.responsetext seems ok (when alert - shows right text) - when using 'if' statement compare string - returns false.

(i 1 wrote server-side code returning string) - after studying string - i've discovered string had "invisible character" first character. character not shown. if copied notepad - deleted first character - won't delete until pressing delete again.

i did charcodeat(0) returned string in xmlhttp.responsetext. , returned 65279.

googling reveals sort of utf-8 control character supposed set "big-endian" or "small-endian" encoding.

so, know cause of problem - but... why character being echoed? in source php use

echo 'the string'... 

and apparently somehow outputs [chr(65279)]the string...

why? , how can avoid it?

to conclude, , specify solution:

windows notepad adds bom character (the 3 bytes: ef bb bf) files saved utf-8 encoding.

php doesn't seem bothered - unless include 1 php file - things messy , strings gets displayed character(65279) prepended them.

you can edit file text editor such notepad++ , use encoding
"encode in utf-8 without bom",
, seems fix problem.

also, can save other php file ansi encoding in notepad - , seem work (that is, in case don't use extended characters in file, guess...)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -