Unexpected characters at the top of the page / headers already sent by BOM
A UTF-8 byte-order mark (BOM) at the start of a PHP file is sent as output, breaking headers, JSON and images.
Seen on:
PHP
Meaning
Some editors save files with an invisible BOM (EF BB BF). PHP outputs it before your code runs. Symptoms: “headers already sent … output started at file.php:1”, JSON parse errors, corrupted downloads.
Common causes
- File saved as “UTF-8 with BOM”
- Hosting control-panel editors adding a BOM
- Copy-pasted config from Windows tools
⚡ Quick fix
- Re-save the file as UTF-8 without BOM
- Find BOMs:
grep -rlI $'^\xEF\xBB\xBF' . - Remove closing
?>tags from pure PHP files
Detailed fix by platform
Linux
sed -i '1s/^\xEF\xBB\xBF//' file.phpremoves a BOM
How to diagnose
- Line 1 — Does the warning point to line 1 of a file?
- Bytes —
head -c 3 file.php | xxd
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026