Page 1 of 1

php require / include adds line break to html

Posted: Fri May 15, 2009 12:33 pm
by lonelycastle
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:

Code: Select all

require "inc/footer.php";
Very basic (and I have tried using parentheses instead).

The footer.php file is very basic too:

Code: Select all

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

Code: Select all

...print "
</div";
?>
beginning of footer.php:

Code: Select all

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

Image

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

Re: php require / include adds line break to html

Posted: Fri May 15, 2009 12:35 pm
by crazycoders
# print "
# </div>

You got it there.... between the " and the </div>, you have a line feed!

Re: php require / include adds line break to html

Posted: Fri May 15, 2009 12:59 pm
by lonelycastle
crazycoders wrote:# print "
# </div>

You got it there.... between the " and the </div>, you have a line feed!
I tried removing the line feed so the footer.php looks like this now:

Code: Select all

<?php
print "</div><div id='footer'>...
but nothing. I also tried removing line feeds in the index.php file near the end, but nothing.

Any other thoughts?

Re: php require / include adds line break to html

Posted: Fri May 15, 2009 1:06 pm
by crazycoders
i copied and pasted your source code and found a character sitting in between the two last div (#city and #content)

you can't see it unless you copy and paste, thats an encoding problem with your editor, the only way would be to rewrite the last two ending </divs> for #city and #content...

Re: php require / include adds line break to html

Posted: Fri May 15, 2009 1:24 pm
by lonelycastle
crazycoders wrote:i copied and pasted your source code and found a character sitting in between the two last div (#city and #content)

you can't see it unless you copy and paste, thats an encoding problem with your editor, the only way would be to rewrite the last two ending </divs> for #city and #content...
I rewrote all the ends of the divs (#city & #content), the opening of the #footer div, and any other div tag near that point, but I still have white space. I also tried rewriting all that stuff in a basic text editor, but no luck.

Any thoughts?

Re: php require / include adds line break to html

Posted: Fri May 15, 2009 1:32 pm
by crazycoders
Open it in another editor, you might see the faulty character. I saw it when i copied it from the web but the source code didn't show it, it was only when i copied the info from firefox's sourceview that i could see it.

You can use UltraEditor to find that char, i often find this software usefull for this kind of problem!

Re: php require / include adds line break to html

Posted: Fri May 15, 2009 1:48 pm
by lonelycastle
Alright . . . not sure what I did, but I fixed it. I just copied the footer.php code, created a new file, saved it over the old footer.php and it worked . . .

Thanks for you help!