php require / include adds line break to html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lonelycastle
Forum Newbie
Posts: 5
Joined: Sun Sep 14, 2008 4:33 pm

php require / include adds line break to html

Post 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.
Last edited by Benjamin on Fri May 15, 2009 12:37 pm, edited 1 time in total.
Reason: Changed code type from text to php.
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: php require / include adds line break to html

Post by crazycoders »

# print "
# </div>

You got it there.... between the " and the </div>, you have a line feed!
lonelycastle
Forum Newbie
Posts: 5
Joined: Sun Sep 14, 2008 4:33 pm

Re: php require / include adds line break to html

Post 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?
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: php require / include adds line break to html

Post 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...
lonelycastle
Forum Newbie
Posts: 5
Joined: Sun Sep 14, 2008 4:33 pm

Re: php require / include adds line break to html

Post 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?
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: php require / include adds line break to html

Post 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!
lonelycastle
Forum Newbie
Posts: 5
Joined: Sun Sep 14, 2008 4:33 pm

Re: php require / include adds line break to html

Post 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!
Post Reply