Last updated: August 29, 2026.
A UTF-8 byte order mark is the three-byte sequence EF BB BF at the beginning of a file. UTF-8 does not require byte-order information, although some editors add the sequence as a signature.
Common symptoms
Browsers usually tolerate a BOM in HTML. It is more troublesome when bytes must begin with exact syntax.
- PHP reports output before headers.
- A CSV importer sees an invisible prefix in the first header.
- A strict JSON consumer rejects the document.
- Concatenated files contain BOM bytes in the middle.
Remove it only at byte zero
Do not delete the same byte sequence elsewhere in the file.
<?php
$data = file_get_contents(__DIR__ . '/input.txt');
if ($data === false) throw new RuntimeException('Unable to read file.');
$bom = "\xEF\xBB\xBF";
if (str_starts_with($data, $bom)) {
$data = substr($data, 3);
}
file_put_contents(__DIR__ . '/without-bom.txt', $data, LOCK_EX);Choose deliberately
UTF-8 without BOM is normally the least surprising choice for web source and PHP files. If another system requires a BOM, add it only at that export boundary and test the receiver.
Confirm the BOM before removing it
A UTF-8 BOM is meaningful only at the beginning of a byte stream. Check the first three bytes rather than searching and deleting the same sequence throughout a document, where it could be legitimate data.
After removal, verify the first CSV header, JSON parsing, and any PHP header calls that previously failed. Keep one untouched copy so a conversion can be repeated safely.
- Remove exactly EF BB BF at byte zero.
- Write the output atomically when possible.
- Configure the editor to save web source as UTF-8 without BOM.
Keep the byte encoding, declaration, storage, and decoder consistent. When diagnosing a problem, preserve the original input and change one boundary at a time so the actual cause remains visible.
Continue with CSV encoding, mojibake troubleshooting, and HTTP charset.
Reference: Unicode byte order mark FAQ.