Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accented letters are not displayed correctly on the server, even if the encoding is correct

i wrote some html with utf-8 charset. in the head of the html there is also a

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 

everything works fine in local, but when i upload files to the server, i see all my letters

àèìòù etc

distorted.

anybody know how could it be the problem? is possible that the server force a charset that isn't utf-8?

thanks a lot

like image 652
Luke Avatar asked Sep 06 '25 03:09

Luke


2 Answers

Try saving the actual file with utf-8 encoding. That did the trick for me. I use PHPStorm as editor: File->File Encoding->utf-8

like image 196
Laura Chesches Avatar answered Sep 07 '25 20:09

Laura Chesches


Actually the META tag is not all you need for correct UTF-8 encoding. Your server might still send the page as Content-Type: text/html; charset=ISO-8859-1 in the header of the page.

You can check the headers e.g. with the Live HTTP Headers Firefox add-on.

There is a lot of secret sauce with UTF-8 encoding and making it work, you might want to go through this page (UTF-8: The Secret of Character Encoding) which explains everything you need to know and gives you advice on how to solve encoding problems.

To answer your question: Yes it is possible to force the server to use UTF-8, e.g. by using the PHP headers() function like so:

header('Content-Type:text/html; charset=UTF-8');

like image 22
Dennis G Avatar answered Sep 07 '25 22:09

Dennis G