SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation 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:

    Code:
    
    <blank line>
    <blank line>
    <blank line>
    <!-- --><!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:

    PHP Code:
    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,

    PHP Code:
    print $html
    I tried,

    PHP Code:
    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.
    John

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    One quick test you should do:

    print 'test'.$html;

    See if the white spaces appear before or after test.

  3. #3
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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...)
    John

  4. #4
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by PHP John View Post
    ...

    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.
    ictus==""

  5. #5
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ServerStorm View Post
    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.
    John

  6. #6
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    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.
    John

  8. #8
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP John View Post
    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.

  9. #9
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    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.
    John

  10. #10
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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.

  11. #11
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    John


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •