Home html Questions instead of Russian letters

Questions instead of Russian letters

Author

Date

Category

Hello.


Answer 1, authority 100%

1) for Apache in .htaccess :

AddDefaultCharset utf-8

2) for nginx in the config:

charset utf8;

3) in a html document :

& lt; head & gt;
  & lt; title & gt; & lt; / title & gt;
  & lt; meta http-equiv = "Content-Type" content = "text / html; charset = utf-8" & gt;
& lt; / head & gt;

html 5 version:

& lt; meta charset = "UTF-8" & gt;

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

5) if using PDO:

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

6) if you are still using procedural database access, then:

mysql_query ('SET NAMES "utf8"');

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

encoding


Answer 2, authority 10%

If you don’t understand the encoding from the base, you can, for example, convert iconv all the variables on the fly on a low-loaded project.

Update

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

somewhere like this:

$ in – string in any encoding


Answer 3, authority 10%

My scripts and html pages for them were spinning on a Windows server, and then everything was transferred to Linux and there were rhombuses with questions instead of Russian.
At first I found an option in the net through notepad ++ to save the html falik in a special encoding.
But this is not the case with everyone.
The solution is, go to the Apache httpd.conf file.
(I have default /etc/httpd/conf/httpd.conf)
And there at the beginning there is the AddDefaultCharset UTF-8 parameter
I replaced UTF-8 with windows-1251
and then restarted the server
systemctl restart httpd
and Russian has worked on the pages in the browser.


Answer 4

The problem is most likely in the HTML coding of the editor you are using. The editor can set the encoding of the recorded file in accordance with the language version of Windows. For example, on the English version, the editor can write in 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 the default for most blogs today, etc. HTML page starts with tags like

& lt;! DOCTYPE html & gt; & lt; html & gt; & lt; head & gt; & lt; meta http-equiv = "Content-Type" content = "text / html; charset = utf-8" / & gt;

Then the text editor should write in UTF8:

 questions instead of Russian letters

In the HTML editor, the setting may be during Save, or it may be somewhere in Settings, or it may not exist at all.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions