title: Php echo whole page HTML override
body: <p>I am trying to make a specific webpage 'echo' an entire new HTML page while 'overwriting' anything that is set in the 'requested page'. Let's say that it has some form of content in it, I want the 'echoed' page to completely replace it, <code>&lt;head&gt;</code> tags and everything.<br>
  Similar concept is used (from what I understand) by various template engines. They however use a structured HTML and fill it with data, meanwhile I want dynamic creation of the HTML structure throughout the file, which will be aggregated into a string and then 'created' into an HTML to be displayed to the user.</p>
  
  <pre><code>&lt;?php
      $htmlcontent = "\n";
      $htmlcontent .= "&lt;html&gt;\n";
      $htmlcontent .= "&lt;head&gt;\n";
      $htmlcontent .= "&lt;style&gt; body {\n";
      $htmlcontent .= "            background-color: red;\n";
      $htmlcontent .= "        }\n";
      $htmlcontent .= "&lt;/style&gt;\n";
      $htmlcontent .= "&lt;/head&gt;\n";
      $htmlcontent .= "&lt;body&gt;\n";
      $htmlcontent .= "&lt;div style=\"background-color:yellow; width:200px; height:200px; position:absolute\"&gt; Some text &lt;/div&gt;\n";
      $htmlcontent .= "&lt;script&gt;\n";
      $htmlcontent .= "alert(\"script has run!\");\n";
      $htmlcontent .= "&lt;/script&gt;\n";
      $htmlcontent .= "&lt;/body&gt;\n";
      $htmlcontent .= "&lt;/html&gt;\n";
  
      echo ($htmlcontent); //EDIT: removed eval() from here
  ?&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong> <em>removed the eval() to avoid confusing the new people, put a comment for those reading post's comments to not get confused by the lack of eval in code.</em></p>
  
  <p>This is the content of the .php page that I am targeting with my request. The idea is, to be able to get an entire new page in the browser, what happens instead is an error that follows (now irrelevant because Eval is removed):</p>
  
  <blockquote>
    <p>Parse error: syntax error, unexpected '&lt;' in
    D:\wamp\www\learningPHP\index.php(30) : eval()'d code on line 2</p>
  </blockquote>
  
  <p>If I just use:</p>
  
  <pre><code>echo $htmlcontent;
  </code></pre>
  
  <p>then I get the page to print out my HTML structure, however it is all printed in a body of a blank HTML page instead of being structured as I need it.</p>
  
  <p><strong>Answer:</strong></p>
  
  <p>The issue was with one of the plug-ins for NetBeans. Upon manually editing the .php file from the server it appears it was carrying the standard HTML tags of a document, as well as some comments on it as well. Removing these fixed the issue.</p>