How can I be sure of the file encoding?

ecantu picture ecantu · Jun 13, 2012 · Viewed 74.4k times · Source

I have a PHP file that I created with VIM, but I'm not sure which is its encoding.

When I use the terminal and check the encoding with the command file -bi foo (My operating system is Ubuntu 11.04) it gives me the next result:

text/html; charset=us-ascii

But, when I open the file with gedit it says its encoding is UTF-8.

Which one is correct? I want the file to be encoded in UTF-8.

My guess is that there's no BOM in the file and that the command file -bi reads the file and doesn't find any UTF-8 characters, so it assumes that it's ascii, but in reality it's encoded in UTF-8.

Answer

Green Lei picture Green Lei · Jan 19, 2015
$ file --mime my.txt 
my.txt: text/plain; charset=iso-8859-1