This is most often not caused by leading but by trailing whitespace. Lots of old PHP code still closes down code at the end, which then all too often has a stray newline:
<?php
// Lot of source code
?> <----- and a newline here which is the culprit!
To avoid this issue, never close files with ?>
- PHP doesn't need it and will just stop parsing at EOF, thus implicitly avoid this 'garbage' in the output.
As for finding the files causing it - good luck, I'd start with combing any custom extensions for this and just removing all ?>
markers that you can find.
As an alternative, you can probably 'fix' it by adding a single ob_start()
call to your index.php
, and then in the template containing the doctype executing ob_end_clean()
- this puts all intermediate output in the output buffers, and then trashes it.