You moved a site to new hosting or edited an old file, and suddenly the Uzbek and Russian text turns into "Сайт", "Сайт" or "Ñàéò". This is called mojibake. In most cases nothing is lost: the bytes are still there, they are just being read with the wrong encoding. The first job is to find out at which step the encodings got mixed up.
Reading the pattern
The shape of the garbage tells you a lot. Here is how the Russian word "Сайт" looks under different mistakes:
| On screen | What happened |
|---|---|
| Сайт | UTF-8 text read as Latin-1 / Windows-1252 |
| Сайт | UTF-8 text read as Windows-1251 |
| Ñàéò | Windows-1251 text read as Latin-1 |
| ���� or ???? | Windows-1251 read as UTF-8, or the database could not store the character |
Question marks coming from the database usually mean the text was lost when it was saved, and only a backup can restore it. In the other cases the bytes are intact.
Cause 1: file encoding does not match the header
Older sites were often written in Windows-1251, while a modern server sends charset=UTF-8. Check and convert files over SSH, writing to a new file so the original is kept:
file -i index.php
iconv -f WINDOWS-1251 -t UTF-8 index.php > index.utf8.php
mv index.php index.cp1251.bak && mv index.utf8.php index.php
file does not always detect 1251 correctly, so verify by opening the page. Once everything is UTF-8, declare it consistently: put <meta charset="utf-8"> at the top of <head>, and send the header from PHP or Apache:
header('Content-Type: text/html; charset=utf-8');
# .htaccess
AddDefaultCharset UTF-8
Cause 2: the BOM
Some Windows editors add an invisible byte order mark (EF BB BF) to UTF-8 files. In PHP files it shows up as "" at the top of the page or triggers "headers already sent". Re-save the file as UTF-8 without BOM, or strip it:
grep -rl $'^\xEF\xBB\xBF' --include=*.php .
sed -i '1s/^\xEF\xBB\xBF//' config.php
Cause 3: the database connection
If static text is fine but product names and news from the database are broken, the PHP-MySQL connection is using the wrong charset. Declare it explicitly:
$pdo = new PDO('mysql:host=localhost;dbname=example_db;charset=utf8mb4', $user, $pass);
$db->set_charset('utf8mb4'); // mysqli
The tricky case is double-encoded data: an old app wrote UTF-8 text through a latin1 connection into latin1 tables for years. phpMyAdmin shows "Сайт", but the old site displays it correctly because the mistake is mirrored both ways; fix the connection and the site breaks. A common repair is to export with --default-character-set=latin1, change the charset declarations in the dump to utf8mb4 and re-import. Details vary per database, so always try it on a copy first.
Example: a school site in Samarkand
A private school in Samarkand ran example.uz on a decade-old CMS with Windows-1251 files. After the move, menus showed diamonds and news from the database started with "Ð". The table pointed to two separate problems. Files were converted with iconv, the database was repaired on a copy and imported, and charset=utf8mb4 was added to the connection.
Quick checklist
- Match the garbage against the table above.
- Check the response
Content-Typein the browser's Network tab. - Separate static text from database text.
- Back up before each change and change one thing at a time.
On sayt.uz hosting you can work with files and databases in the ISPmanager panel opened from the sayt.uz cabinet; if the problem appeared after a migration, a support ticket with the affected page helps find the cause faster.