How to set right page encoding using PHP (UTF-8 HTTP header)?

Quite frequently, many are faced with the problem: incorrect definition of the browser page coding.
The easy way to fix it – set the right page encoding by PHP.
Example (we use the encoding utf-8) ↓

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

Additionally, you can specify the encoding using HTML

Example ↓

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


mysql_query("SET NAMES utf8");

In nginx

    charset utf8;

In Apache

    <Directory /path/to/site/>
    AddDefaultCharset UTF8