How to Fix Garbled Text Like é and ’ (Mojibake)
Why text turns into Café or ’, how to repair double-encoded UTF-8, how to detect a file's real encoding, and how to stop it happening again.
&c=%234338ca&k=developer)
How to Fix Garbled Text Like é and ’ (Mojibake)
You open a CSV export, a database dump or an old web page and see Café instead of Café, ’ instead of an apostrophe, or a line of Ð and Ñ where Russian text should be. This is mojibake, a Japanese word for garbled characters, and it is one of the most common data problems on the web. The good news is that it is often fully reversible. The free Mojibake Fixer and Encoding Detector repairs garbled text and identifies the encoding of text files.
What goes wrong
Computers store text as bytes, and an encoding is the rule that maps characters to bytes. UTF-8, the standard today, stores é as two bytes, C3 and A9. Windows-1252, the old Western European code page, maps every single byte to a character, and in it C3 is à and A9 is ©. So when UTF-8 text is read as Windows-1252, é becomes é. A curly apostrophe uses three UTF-8 bytes, which become â, € and ™.
If that garbled text is saved again as UTF-8 and read wrongly a second time, the damage doubles: é becomes é.
How the repair works
Because Windows-1252 and similar code pages give every byte a character, the original bytes can be recovered. The fixer takes the garbled text, converts it back to bytes using a candidate code page, and decodes those bytes as UTF-8. If the result is valid UTF-8 and reads more naturally, with letters from one alphabet and no stray symbols, it keeps it. It repeats this up to three times for text damaged more than once, and tries Western, Central European, Cyrillic and Mac code pages.
Text that shows question marks or black diamonds instead of Ã-style characters is a different case. There, the original bytes were replaced during conversion and cannot be recovered.
Detecting a file's encoding
For a whole file, the detector reads the raw bytes:
- A byte-order mark at the start identifies UTF-8, UTF-16 or UTF-32 with certainty.
- Every second byte being zero reveals UTF-16 without a mark.
- If the file decodes as valid UTF-8 with multi-byte characters, it is almost certainly UTF-8, since legacy encodings rarely form valid UTF-8 by chance.
- Otherwise, more than twenty legacy encodings are tried, from Windows-1252 and ISO-8859-2 to Shift_JIS, GBK, Big5 and KOI8-R, and ranked by how natural the result looks.
Closely related encodings, such as ISO-8859-1 and Windows-1252, may tie. Check the preview and pick a different one if needed, then download the text saved as UTF-8.
Stopping mojibake at the source
Repair is a rescue, not a fix. The real cure is to use UTF-8 at every step:
- Send
Content-Type: text/html; charset=utf-8and include the meta charset tag in HTML. - Use utf8mb4 as the MySQL character set for tables and connections, since MySQL's older utf8 cannot store emoji.
- Specify the encoding explicitly when reading and writing files in code, rather than relying on the system default.
- When a CSV will be opened in Excel, save it as UTF-8 with a byte-order mark so Excel detects it.
Step by step
- Choose whether to repair text or detect a file.
- Paste the garbled text, or open the file.
- Read the repaired text and the steps that were undone.
- For files, compare the ranked encodings and their previews.
- Download the result as UTF-8.
Privacy
Text and files are processed in your browser and are never uploaded.



