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.
byte order mark 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 not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in PHP
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026