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:

require "inc/footer.php";

Very basic (and I have tried using parentheses instead).

The footer.php file is very basic too:

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

...print "
</div";
?>

beginning of footer.php:

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

    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.

      laserlight;10914586 wrote:

      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:

      include "inc/footer.php";?>

      But that didn't help.

        lonelycastle wrote:

        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.

        lonelycastle wrote:

        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.

          laserlight;10914589 wrote:

          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?

            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:

            </ul><div style='clear:both;'></div></div>&#65279;</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.

              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.

                You're welcome 🙂
                Remember to mark this thread as resolved using the thread tools.

                  laserlight wrote:

                  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

                    a year later

                    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.

                      3 years later

                      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 🙂

                        Write a Reply...