Windows-1252 is a single-byte encoding used by older Windows files and applications. Convert it only when the source encoding is known or strongly established; encoding detection is a guess and can silently choose the wrong interpretation.
Last updated: September 26, 2026.
$bytes = file_get_contents('legacy.txt');
if ($bytes === false) {
throw new RuntimeException('Could not read the input file');
}
$utf8 = mb_convert_encoding($bytes, 'UTF-8', 'Windows-1252');
file_put_contents('converted-utf8.txt', $utf8);Specifying Windows-1252 preserves characters such as curly quotes and the euro sign that occupy the 0x80–0x9F range. Calling the source ISO-8859-1 can produce control characters instead.
Confirm the source before converting
Prefer metadata from the exporting application, a file specification, or a trusted HTTP Content-Type header. mb_detect_encoding() cannot prove which single-byte encoding was intended. The PHP manual explicitly describes it as heuristic guessing.
Inspect a representative sample containing punctuation and non-ASCII letters. Keep the original bytes and write the converted result to a new file until validation is complete.
Validate the UTF-8 result
Use mb_check_encoding($utf8, 'UTF-8'), then open the file in a UTF-8-aware editor and compare known records. Verify smart quotes, em dashes, currency signs, accented names, and any characters important to the business. A valid UTF-8 byte sequence can still represent the wrong text.
The official mb_convert_encoding reference recommends providing the source encoding when it is known. Avoid deprecated utf8_encode(), which only assumed ISO-8859-1 and was never a general converter.
Do not encode the same text twice
If the visible text already contains sequences such as “Français”, the data may have been decoded and re-encoded incorrectly. A normal Windows-1252 conversion is not the same as repairing double-encoded UTF-8. Diagnose the byte history before applying another transformation.