PHP/HTML/CSS:使用 require_once() 时 IE 表现得很奇怪

发布于 2024-07-29 22:31:00 字数 613 浏览 8 评论 0原文

这是我在 PHP 中遇到过的最奇怪的问题。

除一页外,所有页面看起来都正常; 当我第一次看到这个问题时,我认为这是 IE 和样式表的常见问题之一(我在这个页面上有一个特定的 CSS 文件)。 我尝试排除 CSS 文件只是为了确保问题确实存在于该文件中,但事实并非如此。 然后我以为我忘记关闭任何 HTML 标签,所以我多次检查代码,但一切似乎都是正确的。 所以我开始将代码放在注释中并与 IE 进行比较,直到我意识到当我将以下代码放在注释中时,页面本身表现正常:

require_once(PATH_INCLUDES . 'adjacency.php');

这是一个有效的路径,并且该文件只包含一个带有函数的类 - 没有如果 MySQL 查询失败,则以除 die() 之外的任何方式输出。

在 IE 中看起来很奇怪的一些事情如下:

  • 容器通常居中,现在位于左侧。
  • 带有repeat-x 的背景并不完全适用。
  • 菜单中的悬停功能不起作用。

任何人?

编辑:我尝试将 adjacency.php 包含在另一个文件中,但出现了同样的问题。

Now this is the most weird problem I've ever had in PHP.

All pages looks normal except one; when I first saw the problem I thought it was one of these common problems with IE and stylesheets (I've got a specific CSS-file on this page). I tried to exclude the CSS-file just to ensure that the problem really was in this file, but it wasn't. Then I thought I had forgotten to close any HTML tag, so I went through the code multiple times, but all seemed to be correct. So I started to put code in comments and compare with IE until I realized that when I putted the following code in a comment, the page itself acted normal:

require_once(PATH_INCLUDES . 'adjacency.php');

It's a valid path, and the file does just contain a class with functions - there's no output in any way except die() if a MySQL query fails.

Some things that look weird in IE are the following:

  • The container is normally centered, now it's at the left.
  • A background with repeat-x doesn't go all the way.
  • The hover functionality in the menu doesn't work.

Anyone?

Edit: I tried to include adjacency.php in another file, and the same problem occurred.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

把时间冻结 2024-08-05 22:31:00

据猜测,包含文件末尾的结束符“?>”之后很可能有一些空格。 (Zend Framework 建议不要使用 PHP 结束标记的原因之一。)

As a guess, there's most likely some space at the end of the include file after the closing "?>". (One of the reasons that Zend Framework recommends not using the closing PHP tag.)

下雨或天晴 2024-08-05 22:31:00

包含的 PHP 文件是否以 UTF-8 BOM(字节顺序标记)开头? 这是一个不可见的字节序列,有时出现在 Unicode 文本文件的开头,以帮助自动检测 UTF。 不幸的是,PHP 有点幼稚,当它从包含的 PHP 文件中读取 BOM 时,就会输出 BOM。 根据我的实验,IE 可以处理一个 BOM,但是如果 BOM 加倍(如果浏览器请求的 PHP 文件和包含的每个文件都包含 BOM,就会出现这种情况),那么它无法看到文档类型位于开头,并且从而触发怪异模式。

确保您的编辑器配置为在没有 BOM 的情况下保存。

Does the included PHP file begin with a UTF-8 BOM (byte order mark)? This is an invisible byte sequence that sometimes appears at the beginning of a Unicode text file to aid auto-detection of the UTF. Unfortunately, PHP is somewhat naive, and will output the BOM as and when it reads it in from an included PHP file. By my experiment, IE can handle one BOM, but if the BOM is doubled (as will be the case if the PHP file the browser requested and one included each contain the BOM) then it fails to see the doctype as being at the beginning and thus quirks mode is triggered.

Make sure your editor is configured to save without BOMs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文