PHP - include (extra space blank)

? [bolofecal]
9 years ago

0

Someone know why the PHP include function put a blank space in the html web page:

<htm>  
    <head>  
    </head>  
    <body>  
        <?php  
            include("hello-world.php");  
         ?>  
    </body>  
</html>```  

the output is:  
<head>  
</head>  
<body>  


?”

Hello world


9replies
7voices
223views
Rex_Mundi
9 years ago | edited 9 years ago

1

That happened to me a while back man, at the end of my /includes/globals.php file, it had some extra whitespace after the closing tag, removing that fixed the problem for me.

???Roun512 [roun512]
9 years ago

0

What does hello-world.php contain? Can you post the code.

tl0tr
9 years ago | edited 9 years ago

1

In your css file or in the style tag put


* {  
           padding: 0;  
           margin: 0;  
}  

body {  
           padding: 0;  
           margin: 0;  
}  

This should remove the space between two divs.

dloser
9 years ago

2

Actually, there are two issues here. As @Rex_Mundi said, because PHP removes only what’s between the “<?”/“?>” tags, you might end up with unexpected spacing or newlines.

However, the “” is directly from the included file and probably more familiar in hex as FEFF. If not, have a read: http://en.wikipedia.org/wiki/Byte_order_mark

The last can be solved by saving the documents without BOM or by setting the “zend.multibyte” for PHP (I’ve not verified this solution).

? [bolofecal]
9 years ago

0

In this example hello-world.php is just a simple: echo “

Hello world

”;

Thanks evebody, I’ve already tried remove the extra spaces and BOM, but does not work. My quick fix is:

html { margin-top: -15px; }

Thanks so much.

Mr. Cyph3r [MrCyph3r]
9 years ago

2

Well, I’m pretty sure your problem is because of the BOM signature being included at beginning of your file.

Sometimes you can only see the BOM signature with “low level” text editors… I had similar issues in the past and my text editor was not able to get rid of it, even though I was changing the encoding before saving the file.

? [bolofecal]
9 years ago

0

Really is BOM that has been caused the blank space and each “?” is one file that have been included with “include”, I’ve tried remove the BOM just in index page, but now I remove the BOM for all files and the problem was solved. Thanks everybody. All posts help me.

:)

Mr. Cyph3r [MrCyph3r]
9 years ago

0

I knew it! Good job man :)

? [bolofecal]
9 years ago

0

Thanks. Change the value to margin-top causes a different spaces in each browser. Eliminated the BOM is a good solution.

:)

Reply has been removed
You must be logged in to reply to this discussion. Login
1 of 10

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss