Visible Gaps when using PHP Includes

Discussion in 'PHP' started by bavington, Apr 15, 2009.

  1. #1
    Hi everyone, I'm having a problem using PHP includes.

    Essentially I am trying to move away from Dreamweaver Templates and create a site using PHP Includes.

    So Far So Good, however I am getting gaps in Firefox and IE7 (Doesn't happen on Safari) in between PHP Includes.

    These gaps cannot be remedied by CSS or deleting blank lines or spaces.

    The bizzare thing is that even output HTML looks like it shouldn't produce a gap.

    When I copy and paste all of my includes onto a single html page, and upload the to the server, I get no gaps.

    Here is my primary includes page code:

    <?php require('includes/header.php'); ?>
    <title>Hello</title>
    <?php require('includes/header2.php'); ?>
    <h1>Test Page</h1>
    <p>test</p>
    <?php require('includes/footer.php'); ?>
    PHP:
    header PHP is:

    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    PHP:
    Header 2 is:

    <link rel="stylesheet" type="text/css" href="<?php PHP_SELF ?>/css/styles.css"/>
    </head><body>
    PHP:
    and so on.

    Essentially I'm getting about 10-15px gap at the very top of the page. Does anyone know what causes this problem, and how I can fix it?

    The outputted page can be seen here so that you can see the gap:
    http://www.crearedesign.co.uk/contact-us.php

    The White tab at the top should not have that gap above it.

    I'm using Dreamweaver CS4 For Mac.

    Thank you in advance.
     
    bavington, Apr 15, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    This is a css issue and not a php issue. I would mess with the css for the header element or possibly the body element until you get it removed.
     
    jestep, Apr 15, 2009 IP
  3. bavington

    bavington Peon

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It's not a CSS issue. Like I said, If I open all of my include files, copy and paste them onto a single html page, upload the page, there is no gap at the top.

    http://www.crearedesign.co.uk/cont.php

    The gap IMO has something to do with the includes. Both the link in my initial post, and the link just above, are the same files, using the same CSS.
     
    bavington, Apr 15, 2009 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #4
    I suppose here is problem
    Must be:
    <?php echo $_SERVER['PHP_SELF'];?>/CSS_PATH_HERE
    PHP:
    Regards.
     
    koko5, Apr 15, 2009 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    If I use winmerge to compare the 2, the one that displays incorrectly, has hidden characters in it. There is one as the first character in the include file. I can't tell what character it is. Is appears as a dot, and doesn't appear to have any encoding with it.

    What program are you using to write these files?

    [​IMG]
     
    jestep, Apr 15, 2009 IP
  6. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Perhaps it's the Unicode BOM. Make sure to tell your text editor to save files with no BOM.
     
    SmallPotatoes, Apr 15, 2009 IP
  7. bavington

    bavington Peon

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    jestep, thank you for your help, your discovery looks like it could be the problem.

    I'm using Dreamweaver CS4 for Mac to code and upload everything.

    Does anyone know how to 'save files with no BOM.' in Dreamweaver?

    Thanks again to everyone for the assistance.
     
    bavington, Apr 16, 2009 IP
  8. bavington

    bavington Peon

    Messages:
    74
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    KoKo, thanks for your advice, however if I change to your corrected coding the links don't work.
     
    bavington, Apr 16, 2009 IP
  9. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I don't know anything about Dreamweaver (never tried GUI web tools) but there's definitely a BOM at the head of your file:

    % wget -q -O - http://www.crearedesign.co.uk/cont.php | od -a | head -n 1
    0000000   ef  bb  bf   <   !   D   O   C   T   Y   P   E  sp   h   t   m
    Code (markup):
    That EF BB BF is the giveaway.

    I'm surprised Dreamweaver would put it in, as it's so often a problem for web and particularly PHP files. Maybe you'll find something in the preferences or the "save as" dialog about "byte order mark" or "unicode signature". If so, just turn it off.
     
    SmallPotatoes, Apr 16, 2009 IP