Wordpress – HTML文档不是从第一行开始 [英] Wordpress – HTML document does not start at line one
问题描述
我已经为这个问题苦苦挣扎很长时间了,但是我找不到真正的解决方案.问题是< !DOCTYPE html etc...
不在第一行开始,而是在开始前留了四行空白.
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.
我的所有文件(header.php
,index.php
等)在开始之前都没有换行符.
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!
请参阅此处以供参考:view-source: http://2famous.tv/
See here for reference: view-source:http://2famous.tv/
谢谢
推荐答案
这通常不是由 leading 引起的,而是由 trailing 空格引起的.许多旧的PHP代码仍然会在最后关闭代码,然后这些代码常常会出现一个换行符:
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!
为避免此问题,请不要使用?>
关闭文件-PHP不需要它,它将在EOF处停止解析,因此在输出中隐式避免了这种垃圾".
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.
或者,您可以通过向index.php
添加单个ob_start()
调用来修复"它,然后在包含执行ob_end_clean()
的doctype的模板中-将所有中间输出放入输出缓冲区,然后将其丢弃.
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.
这篇关于Wordpress – HTML文档不是从第一行开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!