Why, after moving a website or importing a database, accented letters and other special characters turn into question marks or strange symbols — and how to fix it.
Contents
The cause is almost always the same: one part of the website works in one character encoding and another part works in a different one. These days everything should use UTF-8 (in MySQL it is called utf8mb4). What you see on the page tells you what is wrong.
What you see on the page
- “????” instead of accented letters in text from the database. The characters were lost when the text was saved to the database or when the database was imported. Most often the database was imported in the wrong encoding — import it again, as described below.
- “Café” instead of “Café”, or “Müller” instead of “Müller”. The data itself is intact, but it is being read in the wrong encoding. Usually the website has not told the database which encoding it wants the text in.
- Black diamonds with a question mark. The website files are saved in an old encoding such as ISO-8859-1 or windows-1252, while the page tells the browser it is UTF-8 (or the other way round).
Importing a database
In phpMyAdmin, the Import tab has a “Character set of the file” field. For modern exports, leave it as utf-8. If the file is old, from the days of legacy encodings, choose the encoding it was saved in (for example latin1) — phpMyAdmin will convert the text into the right encoding for you. Create new databases and tables in utf8mb4.
The website and the database speak different languages
Immediately after connecting to the database, the website must tell it that it works in UTF-8. In a CMS this is usually a setting: in WordPress it is the line define('DB_CHARSET', 'utf8mb4'); in wp-config.php. In your own PHP code:
// mysqli
mysqli_set_charset($link, 'utf8mb4');
// PDO
$pdo = new PDO('mysql:host=localhost;dbname=database_name;charset=utf8mb4', $user, $pass);Page encoding
At the start of every page, in the <head> block, there should be the line <meta charset="utf-8">. The website files themselves must also be saved in UTF-8: in an editor on your computer you can see this in the status bar, and change the encoding there too. You can also hint the encoding to the browser for the whole website with the line AddDefaultCharset UTF-8 in .htaccess.
Didn’t find the answer? Ask our support team — we’ll help.