在doctype之前有空白的问题 [英] Problem with whitespace before doctype

查看:104
本文介绍了在doctype之前有空白的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些奇怪的问题,我在两个不同的文件夹中有两份同一网站。在这两个副本之一中有doctype声明之前的空白,所以我有问题与facebook一起工作,因为文档的格式不正确。

I got some strange problem where i have 2 copies of same website in 2 different folders. In one of those 2 copies has whitespace before doctype declaration so i have problems to work with facebook as document is formated incorrectly.

在html之前有一些php计算,但是那里没有回声或其他什么东西。

Before html there is some php calculations, but there is no echo statements or something.

在同一个服务器上的不同文件夹下,有两个标识网站可能会导致这个问题?

What could be cause for 2 identique websites under same server in different folders, one having this issue?

推荐答案

我几乎肯定地确定在PHP包含结尾处有一些尾随空格。

I'm almost positively certain that you have some trailing whitespace at the end of a PHP include. Check there first.

例子:

Example:

<?php
    // header file
    include 'other_file.php';
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"><!-- etc.  -->

然后

Then

<?php
    // other_file.php
    // connects to database, or something,
    // but notice the whitespace after the closing tag
?>



... pretend this text isn't here

我在最后添加了备注以获取stackoverflow的降价编辑器,以显示关闭?>> 标签后的附加行。在包含标签后,PHP会自动截断一个换行符,但是如果您有多个换行符,那么在您的doctype声明之前,它们将被解释为空格。

I added the note at the end to get stackoverflow's markdown editor to show the additional lines after the closing ?> tag. PHP automatically truncates one newline character after the tag in includes, but if you have more than one they will be interpreted as blank space before your doctype declaration.

最简单的修复方法?从所有包含中删除结束标记?> 。这是一种有效的技术,可能是这是您启动和运行的最快方式。

Easiest fix? Remove the closing tag ?> from all of your includes. This is a valid technique, and could be the fastest way for you to get up and running.

这篇关于在doctype之前有空白的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆