[RESOLVED] php require / include adds line break to html
Results 1 to 11 of 11

Thread: [RESOLVED] php require / include adds line break to html

  1. #1
    Junior Member
    Join Date
    May 2009
    Posts
    4

    resolved [RESOLVED] php require / include adds line break to html

    I have a problem which has been occurring on several of the sites I've built lately. It seems when I include the the footer file on each page a line break gets added to the html which isn't good for designs where a color is supposed to be flush with the footer.

    Here's an example:

    http://216.151.1.137/~shopauto/

    here's what the require code looks like:
    PHP Code:
    require "inc/footer.php"
    Very basic (and I have tried using parentheses instead).

    The footer.php file is very basic too:

    PHP Code:
    <?php
    print "
        </div>
        <div id='footer'>
            &copy; 2009 All Rights Reserved.
            Website Design by <a href='http://www.dwstudios.net/' style='color:#666666;'>Darkwater Studios</a>
        </div>
    </div>
    </body>
    </html>"
    ;
    ?>
    It's not a CSS issue (though I know it seems like it is). To illustrate that point I tried to leave the first part of a closing div tag in the file which is including the footer (index.php) and then finished the tag in the footer:

    end of index.php:
    PHP Code:
    ...print "
    </div"
    ;
    ?> 
    beginning of footer.php:
    PHP Code:
    <?php
    print ">
        </div>...
    And this is how it looks in the source code . . . actually, I can't even paste it, I'll have to use a screenshot:

    http://216.151.1.137/~shopauto/images/Picture%201.png

    Any thoughts. My sense is it's something with the DOCTYPE or encoding type or something like that which I don't understand.

  2. #2
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,537
    You could try removing the closing PHP tags to see if that makes a difference (i.e., remove the various instances of <? ). I suspect that blank lines following such closing tags could be the source of your problem.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  3. #3
    Junior Member
    Join Date
    May 2009
    Posts
    4
    Quote Originally Posted by laserlight View Post
    You could try removing the closing PHP tags to see if that makes a difference (i.e., remove the various instances of <? ). I suspect that blank lines following such closing tags could be the source of your problem.
    I'm not exactly sure what you mean. I think I need to close the php, don't I? I assume it will produce an error otherwise.

    I did, though, remove the line break in the php file between the include "inc/footer.php" and the ?> in the index.php file so it looks like this now:

    PHP Code:
    include "inc/footer.php";?> 
    But that didn't help.

  4. #4
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,537
    Quote Originally Posted by lonelycastle
    I think I need to close the php, don't I? I assume it will produce an error otherwise.
    Read the PHP manual on Instruction separation.

    Quote Originally Posted by lonelycastle
    I did, though, remove the line break in the php file between the include "inc/footer.php" and the ?> in the index.php file so it looks like this now:
    That would make no difference since that line break is/was within the PHP code part of the file, and thus it is not significant.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  5. #5
    Junior Member
    Join Date
    May 2009
    Posts
    4
    Quote Originally Posted by laserlight View Post
    Read the PHP manual on Instruction separation.


    That would make no difference since that line break is/was within the PHP code part of the file, and thus it is not significant.
    Alright, learn something new everyday. Unfortunately it didn't fix the problem. i removed the closing php tags (?>) from the footer.php, the index.php file, and all the other files included by the index.php file (at the top of the page). But I still have that damn white space.

    Thoughts?

  6. #6
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,537
    Okay, this is weird. Looking at your source of your example in Firefox's source browser, the client side output looks fine and dandy. Copying over the source to my text editor reveals that there is extra whitespace on this line, in between the second and third closing div tags:
    Code:
    </ul><div style='clear:both;'></div></div></div><div id='footer'>
    My hex editor tells me that the whitespace corresponds to three bytes with values 0xEF, 0xBB and 0xBF. I would conclude that somehow, you managed to add these bytes into your source. The problem is probably not even related to PHP.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  7. #7
    Junior Member
    Join Date
    May 2009
    Posts
    4
    Yeah, someone else on another forum just spotted that too. I ended up just copying the footer.php file to a new file part by part, then saved over the old footer.php file and it worked fine. I don't understand it, but I'll take it.

    Thanks for your help.

  8. #8
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,537
    You're welcome
    Remember to mark this thread as resolved using the thread tools.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  9. #9
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,843
    Quote Originally Posted by laserlight
    My hex editor tells me that the whitespace corresponds to three bytes with values 0xEF, 0xBB and 0xBF. I would conclude that somehow, you managed to add these bytes into your source. The problem is probably not even related to PHP.
    Yup, whatever editor was used to save footer.php saved it as UTF-8 and included an unnecessary Byte Order Mark in the process. Editor configuration fault, in other words. See http://bugs.php.net/bug.php?id=40072
    Last edited by Weedpacket; 05-16-2009 at 02:05 AM.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  10. #10
    Junior Member
    Join Date
    Sep 2010
    Posts
    1
    I ran into the same problem--line breaks before and after my include statements (on the client).

    I'm using SmartFTP as my editor and its default file format is UTF8.

    The solution? I had to change my file format is ANSI. After converting, all my mysterious line breaks disappeared.

  11. #11
    Junior Member
    Join Date
    May 2013
    Posts
    1
    Hi everyone,

    sorry for digging so deeply, but I went here with the same problem as you had, and found the same 3 hex codes in the middle of the page.

    This solved my problem (thanks !) and if I want to post here, this is because I got more info on the weird 0XEFBBBF.

    Theese 3 bytes are the "BOM", or "byte order mask" of the file. When you encore a file in UTF8 (with notepad++) for exemple, you can choose to encode them in "UTF8" or "UTF8 (without BOM)". Chose the second option and the three bytes won't be in your file again.

    More info about the BOM :
    http://en.wikipedia.org/wiki/Byte_order_mark

    hope this will help future readers of this topic

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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