Hello.

I started translating the site into Russian, but a problem arose - questions began to show instead of Russian letters. The problem is connected, I think, with mysql, since inside the site questions appear instead of letters, only when there is data from the database. In the database I put utf-8_bin, it also did not help. What could be the problem?

  • and on the site what encoding? - Perkovec
  • There are many factors here: file encoding, meta tag encoding, base encoding, availability of a SET NAMES utf-8 or cp1251 request, header () headers, and so on. you need to check everything - mountpoint
  • htaccess is written utf-8, in html text / html; charset = utf-8 @Perkovec @mountpoint - fikos
  • Russian letters are normally displayed in the database? - mountpoint
  • yes @mountpoint - fikos

3 answers 3

1) for Apache in .htaccess :

AddDefaultCharset utf-8 

2) for nginx in the config:

 charset utf8; 

3) in the html-document :

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

html version 5:

 <meta charset="UTF-8"> 

4) all entities (tables) should be set to utf8_general_ci

5) if using PDO:

 new \PDO( 'mysql: host=localhost; dbname=db; charset=utf8;', 'user', 'pass' ) 

6) if you still use procedural access to the database, then:

 mysql_query('SET NAMES "utf8"'); 

7) in your editor / IDE save the file in utf8 encoding

  • one
    $ conn-> set_charset ("utf8"); // you had mysqli_query ('SET NAMES "utf8"') elsewhere return $ conn; } Fixed in ru / inc / db.php, earned - fikos
  • If you use SET NAMES "utf8" and, in general, the utf8 encoding, then you will not have smiles and other modern unicode in your database. Not just will not be saved, but requests will end in error. Think again, already 21 century in the yard! - sanmai

If you do not understand the encoding from the database, then you can on a low-loaded project, for example, convert iconv on the fly all the variables.

Update

 $out=iconv( mb_detect_encoding($in), 'UTF-8', $in) 

somewhere like this:

$in - a string in any encoding
$out - utf-8 string

  • The site is not highly loaded @ Mikhail Kolev - fikos
  • 6
    congratulations, now your project is highly loaded) - ArcherGodson

The problem is most likely in the coding of the HTML editor you are using. The editor can set the encoding of the recorded file in accordance with the language version of Windows. For example, in the English version, the editor can write to ANSI, which is not understood by browsers.

Solution: The HTML encoding of the page must match the encoding specified in the HTML tag. For universal UTF-8 which is currently used by default in most blogs, etc. HTML page starts with type tags

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

Then the text editor should write to UTF8:

questions instead of Russian letters

In the HTML editor, the setting may be at the time of Save, and it may be somewhere in the Settings, and may not be at all.