Website Encoding

Hello, I’ve been suffering for a long time, but I can’t find a complete answer to this question.

  1. What encoding should be in the database (MySQL, if Russian, Kazakh and English languages ​​are used), and do I need to write settings in .htacces and what should I write exactly?
  2. What is the encoding in the html page and how to correctly write it there for all cases?
  3. In a php file?
  4. In PHP when creating xml files?
  5. Do I need to write encoding in JavaScript, in CSS?

I’ve been studying web programming languages ​​for like a year now, and every time I put my work on the server, there is a problem with the language. )

Answer 1, authority 100%


— mysql: specify UTF8 encoding everywhere and collation utf8_general_ci


1) after connecting to the database

mysql_query('SET NAMES UTF8;');

2) optionally add before output

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

— ide(editors): check encoding to be unicode. It is desirable to set it by default.

— apache: add line

to .htaccess file

AddDefaultCharset UTF8

— html: in <head></head> add tag

<meta http-equiv="content-type" content="text/html; charset=utf8" />

Answer 2, authority 33%

You don’t need to write anything in css and js. Make it utf8 everywhere. In php, add after connecting to the database:


In the database, the table and fields are utf8. Write in the header

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

Answer 3

What browser are you using? Maybe it’s forced?
in script instead of mysql_set_charset(‘utf8’); you can try
mysql_query(“set character_set_client=’utf8′”);
mysql_query(“set character_set_results=’utf8′”);
mysql_query(“set collation_connection=’utf8_general_ci'”);

Something like this…that’s what I did for cp1251.

By the way, I recommend using the PHP Expert Editor (registration is free for Russians)

Answer 4

mysql_query(“SET NAMES utf8”);
you write it in php files, and Russian and English are provided for you

Answer 5

if you use utf8 encoding, then the encoding of php, html files should be utf8

Answer 6

try to open the page,
and if the coding is not correct there.. = test with the coding (switch it in the browser)
in ie, this menu is > view > encoding.
in mozilla fx or the same place.
and that’s what goes – put this one ..