White space at top of page source when using ob_start()

I’ve stepped into this project, and I’ve been asked to solve a sticky issue, and I feel like I’m chasing a ghost. Hopefully some of you will have seen this before and can give me some direction.
The problem we are facing is the rendered website does not play well with IE9. JavaScript functionality dies when viewed in IE9. It does fine in IE8 and 10.

When looking at the source, I see the following:

[COLOR=gray][FONT=Consolas]
<blank line>
<blank line>
<blank line>
[/FONT][/COLOR]<!-- --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

In the code that generates the page, the original programmer is using this:

ob_start(); // Start the Output buffer
include $DIR['templates'].'/'.$template;  // include and process the file
$html = ob_get_clean(); // get the contents of the output buffer

The template being used has no white space above the DOCTYPE tag.

When $html is printed/echoed the code is simply,

print $html;

I tried,

print trim($html);

but, that didn’t strip those top lines.

The reason I’m focused on those lines is because it appears that it’s messing with the headers and IE9 is freaking out.

I’m really at a loss and could use some help.

Thanks.

One quick test you should do:

print ‘test’.$html;

See if the white spaces appear before or after test.

Thanks. Did that. The “<!-- –>” was the test text, and it came in below the blank lines.

There may be another reason that this is not working, and it may have nothing to do with the code.

I have been testing this in IE9 on a Windows 7 HOME edition, and it worked.

When tested in IE9 on a Windows 7 PROFESSIONAL edition, it did not.

Same versions of IE9 down to the last digit.

What in the world would be the cause of the problem on the Professional version as opposed to the Home version? (right now there are more indicators that this is the issue instead of the coding…)

Could it be the defaul CSS style sheet that has a large amount of padding/margins assigned by default?

Is it possible that you can gain access to another IE9 on a Windows 7 Pro to see if this is consistent there?

It would really stink, investing a lot of time or changing things when as you alluded to, you are not even sure the code is the problem.

I agree.

We found one computer with Windows 7 Pro installed that would run the site as expected in ie9. All others would not (they also have Win 7 Pro and ie9).

And we’re pulling out our hair trying to figure out what is different on that one stupid box that would allow it to work when all others do not. (can you tell I’m frustrated? ;))

I am hoping that someone else has encountered this and found a solution… but so far, it’s not looking very hopeful.

Thanks.

Well, assuming you did exactly as I suggest (except with HTML comment vs “test”), then conclusion would be that the white space is BEFORE the template layer. So your search should be all PHP files loaded before hand, which have white spaces outside of PHP tags.

I agree, and I’m currently going through all the code trimming spaces and such.

If found, I sincerely hope that it clears this up, but it does not explain the inconsitancy between different computers running the same IE 9.

I would assume you have 3 files which probably end liek this:

?>
{blank line}

causing the 3 blank lines.

Well… I went through ALL of the .php scripts and found several included files that did NOT have a closing tag (?>) for the script. I also found several scripts with trailing lines after the closing tag.

Cleaning this up, cleaned up the blank lines, and the IE 9 issue.

Thanks guys, for the feedback.

Just to let you know, not closing the PHP tag is actually a better way as it prevents these blank space issues. I always close it though because I’m OCD like that and it just looks unbalanced.

Hmmm… This is so odd.

These changes worked on my boss’s installation of IE 9, but not on others.

Then, someone said, “Hey! It’s not working on mine!” She had IE8.

There was no error notification on IE9, but there was on IE8. “console.log” was not recognized.

I commented out all of the instances of the “console.log” call in the javascript and the site functionality began working as it should in all installations of IE9 and IE8.