1

If I make this the code of index.php:

<!DOCTYPE HTML>
<html>
    <head>
        <style type="text/css">
            *{
                margin: 0px;
            }
    
            header{
                height: 100px;
                background: #000000;
            }
        </style>
    </head>
    <body>
        <header>
        </header>
    </body>
</html>

then it displays how I want it, like this: correct

But then, when I change index.php to:

<?php
require "./includes/header.php";
?>

and then have header.php as the exact same code that I posted just then, a blank space appears above the header:

incorrect

Why?! What could cause a page with the exact same HTML (I've checked multiple times) to display different when included via PHP, especially since the browser wouldn't even have any knowledge of what goes on server-side...

Anyone know?

Community
  • 1
  • 1

2 Answers2

0

It's encoding problem, you need to save your file with "UTF-8 without BOM". Look at PHP include causes white space at the top of the page

Community
  • 1
  • 1
Tib
  • 2,553
  • 1
  • 27
  • 46
-2

Use this

    require_once('includes/header.php');

and header.php file must inside includes folder.

  • Not true at all, you're free to `require` whatever PHP you want. Besides that, parentheses are unnecessary for language constructs like `require`. – Aeveus Nov 16 '13 at 11:02