views:

255

answers:

2

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.

+5  A: 

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.)

middaparka
probably the cause, any output before the doctype triggers quirksmode in IE6
I.devries
I thought that too, so I checked that and even, in IE, right-click->source. Nothing is before the doctype.
Ivarska
I'd check the beginning and end of the include file just to be sure - it might be a non-display character that's causing the problem.
middaparka
Checked and confirmed - there's no character before or after the PHP section.
Ivarska
I'm curious about this not 'closing the php tag'. Could you please provide a link to this statement? I'd like to read it in context. Thanks!
EvilChookie
Please double-check. Save each version and compare byte for byte using fc (command-line utility that comes with Windows) or a similar tool. Also try viewing the saved versions in your browser and see whether the same thing happens. And see also my answer.
Stewart
What files should I compare with fc?
Ivarska
The HTML file generated by your PHP script with the require_once, and the HTML file generated by your PHP script without the require_once. Make sure you save each as "Webpage, HTML only".
Stewart
@EvilChookie - It's in the coding standards at http://framework.zend.com/manual/en/coding-standard.html - See the "PHP File Formatting" section.
middaparka
+1  A: 

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.

Stewart
I do save my files as UTF-8. I'm using UltraEdit, and DOM seems to be disabled.
Ivarska