Investors

Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Troubleshooting page encoding issues

This guide is intended for developers and webmasters who are experiencing display issues with special characters (e.g., accents, Arabic characters, Chinese characters, emojis, etc.) on a website or in a database hosted by Infomaniak.

 

Introduction

  • Common causes of incorrectly displayed characters that appear instead of special characters or emojis like ??:
    • PHP connection in utf8 instead of utf8mb4
    • MySQL table or column in latin1 or utf8 instead of utf8mb4
    • SQL file encoded differently from the import setting
    • Incorrectly encoded HTML/CSS/JS files
    • Missing or incorrect charset declaration on the HTML, PHP, or HTTP side
  • Common solutions:
    • Use utf8mb4 everywhere: database, connections, tables, columns, files, headers
    • Validate the encoding of all files and dumps
    • Test the display of emojis, accents, and other multilingual characters
  • Also, refer to this other guide to force a different encoding when connecting to a MySQL database.

 

Use a text editor that supports saving in UTF-8 without BOM (Visual Studio Code, Sublime Text, Notepad++...).

 

1. Use UTF-8 or UTF-8MB4 everywhere

MySQL's utf8 encoding does not support 4-byte characters, such as emojis. These will be displayed as ??. Therefore, you should use utf8mb4, which is a true, complete implementation of UTF-8.

 

2. HTML – Correct encoding declaration

In the <head> of your HTML pages:

<meta charset="UTF-8">

Also, make sure that the CSS/JS files are saved in UTF-8 (without BOM).

 

3. PHP – Force UTF-8 or UTF-8MB4

a) HTTP Headers

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

b) MySQL Connection (MySQL API)

$connection = mysql_connect($host, $user, $pass);
mysql_set_charset('utf8mb4', $connection);

c) PDO Connection

 $dsn = "mysql:host=localhost;dbname=ma_base;charset=utf8mb4";
$pdo = new PDO($dsn, $user, $pass, [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);

 

4. MySQL Database

a) Configuration in phpMyAdmin

  • The database, tables, and columns must be in utf8mb4_unicode_ci or utf8mb4_general_ci.
  • In the Operations tab, choose utf8mb4_unicode_ci for the collation.

b) Useful SQL commands

ALTER DATABASE ma_base CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
ALTER TABLE ma_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

c) After PHP connection

mysqli_query($conn, "SET NAMES 'utf8mb4'");
mysqli_query($conn, "SET CHARACTER SET 'utf8mb4'");

 

5. .user.ini / .htaccess file

To force server-side encoding (Apache):

AddDefaultCharset utf-8
Header set Content-Type "text/html; charset=utf-8"
# Pour PHP
php_value default_charset UTF-8
php_value mbstring.internal_encoding UTF-8

 

6. Import / export of SQL dumps

Errors such as é becoming ? or an emoji ☺ becoming ?? often stem from an encoding mismatch.

Check the encoding of the SQL file before importing. Use iconv if necessary:

iconv -f ISO-8859-1 -t UTF-8 dump.sql > dump_utf8.sql

In phpMyAdmin, specify the import encoding (e.g. UTF-8, UTF-8MB4 or latin1) according to the file.


Has this FAQ been helpful?