In php.ini (this is the default after PHP 5.6):
default_charset UTF-8
When building a web page:
header('Content-type: text/plain; charset=UTF-8');
When connecting to MySQL:
(for mysql:) Do not use the mysql_* API!
(for mysqli:) $mysqli_obj->set_charset('utf8mb4');
(for PDO:) $db = new PDO('dblib:host=host;dbname=db;charset=utf8', $user, $pwd);
In code, do not use any conversion routines.
For data entry,
<form accept-charset="UTF-8">
For JSON, to avoid \uxxxx
:
$t = json_encode($s, JSON_UNESCAPED_UNICODE);