DOCTYPE and HEAD loading incorrectly in PHP
<p>Below is the my index page.  $page is defined at the top, and then the sections of the page (header, menu, body &amp; footer) are changed out at the bottom.</p>

<p>The problem I'm running into is that the DOCTYPE and  data are not loading first, before the remaining page content.  This causes the browser to run in quirks mode.</p>

<p>Let me know if/how I can make this question clearer.</p>

<p>Thanks in advance for your time!</p>

<p>UPDATE:
I have removed all PHP tags, and set the require('includes/....') to variables to eliminate on page load.  The DOCTYPE still refuses to load.  Code below reflects the changes.</p>

<p>UPDATE 2:
DOCTYPE is now directly butted up to the $page variable, eliminating all whitespace.  Also, when viewing in the browser, I noticed that  is shown, even though the opening  is not.  All stylesheets and other  content is rendered inside the  of the page.</p>

<p>SOLUTION:
The solution could have been multiple factors, as pointed out by multiple people (Such as newlines being generated before the DOCTYPE), but I can only say for sure that the final answer was as follows:
The external documents being called into the $page were not set to variables.  Thus, they seemed to be loading before the page.  Once I set the external includes/requires to variables in their respect documents, the DOCTYPE loaded properly.  I can't thank you all enough for your time.</p>

<pre><code>&lt;?
require('includes/functions/get_content.php');
$header=require('includes/header.php');
$footer=require('includes/footer.php');

$page='&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;

&lt;head&gt;
&lt;title&gt;Website Name&lt;/title&gt;

&lt;link rel="stylesheet" href="/css/primary_layout.css" type="text/css" charset="utf-8" /&gt;
&lt;script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.min.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="bodyContainer"&gt;                
%HEADERS%

%MENU%

&lt;div id="bodyContentPane" role="main"&gt;
%BODY%
&lt;/div&gt; &lt;!-- Close bodyContentPane --&gt;
%FOOTER%
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;';

//############### LOAD BODY CONTENT and SET CATEGORY ###############
$p = $_GET['p'];
switch ($p){ 
case "port-a-cool":
$filename='includes/content1.html';
$data=get_content($filename);
$product_category = '1';
$body=$data;
break;

case "radiant-heaters":
$filename='includes/content2.html';
$data=get_content($filename); 
$product_category = '2';
$body=$data;
break;

default:
$body= include('includes/index.php');
break;
}

//############### DEFINE CONTENT TO LOAD BY CATEGORY ###############
$i = $product_category;
switch ($i){
case "1":
$menu=include('includes/menus/content1.php');
break;
case "2":
$menu=include('includes/menus/content2.php');
break;  }

// ############### CHECK FOR UNDEFINED SUB MENU ###############
if ($menu=="")
$menu = include ('includes/menus/default.php');

$page=str_replace('%HEADER%',$header,$page); 
$page=str_replace('%MENU%',$menu,$page); 
$page=str_replace('%BODY%',$body,$page);
$page=str_replace('%FOOTER%',$footer,$page); 
echo $page;
?&gt;
</code></pre>
