Answer 1, authority 100%
1) for Apache in .htaccess :
2) for nginx in the config:
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
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
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.
$ 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.
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:
In the HTML editor, the setting may be during Save, or it may be somewhere in Settings, or it may not exist at all.