问题
I've been struggling with this problem for a long time now, but I cannot really find the solution. The problem is that < !DOCTYPE html etc...
does not start at the first line, but leaves four blank lines before it starts.
All my files (header.php
, index.php
etc) have no line breaks before they start.
Anyone with any similar problems/experiences out there? It would have been of huge help!
See here for reference: view-source:http://2famous.tv/
Thank you
回答1:
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.
来源:https://stackoverflow.com/questions/20714356/wordpress-html-document-does-not-start-at-line-one