Is this violating the DRY principle? I feel that I am repeating myself a lot with this HTML/PHP code. Am I right, and is there a maintainable way of reducing the amount of repetition in the code?

mydomain/index.php:

&lt;!DOCTYPE HTML&gt;
&lt;?php $root="/mywebdir"; ?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;?php include("$root/inc/meta.php"); ?&gt;
&lt;meta name="description" content="Some description" /&gt;
&lt;meta name="keywords" content="some,home,page,keywords" /&gt;
&lt;title&gt;Home - This Website&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="main"&gt;
&lt;?php include("$root/inc/header.php"); ?&gt;
&lt;?php include("$root/inc/nav.php"); ?&gt;
&lt;div&gt;
&lt;h2&gt;Home&lt;/h2&gt;
&lt;p&gt;Introduction.&lt;/p&gt;
&lt;p&gt;Some content.&lt;/p&gt;
&lt;p&gt;More content.&lt;/p&gt;
&lt;/div&gt;
&lt;?php include("$root/inc/footer.php"); ?&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;


mydomain/somedir/index.php:

&lt;!DOCTYPE HTML&gt;
&lt;?php $root="/mywebdir"; ?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;?php include("$root/inc/meta.php"); ?&gt;
&lt;meta name="description" content="Some description" /&gt;
&lt;meta name="keywords" content="some,keywords,about,this,page" /&gt;
&lt;title&gt;Some Page - This Website&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="main"&gt;
&lt;?php include("$root/inc/header.php"); ?&gt;
&lt;?php include("$root/inc/nav.php"); ?&gt;
&lt;div&gt;
&lt;h2&gt;Some Page&lt;/h2&gt;
&lt;p&gt;Some content about this page.&lt;/p&gt;
&lt;/div&gt;
&lt;?php include("$root/inc/footer.php"); ?&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Consider using existing template systems to help you that support inheritance. Template inheritance isn't a strict requirement, but is a powerful feature that makes maintaining templates a lot easier. Twig is easy to use, and feature-rich.

If you want to go it your own way, you could simply implement the use of layout files:

layout_default.php

&lt;!DOCTYPE HTML&gt;
&lt;?php $root="/mywebdir"; ?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;?php include("$root/inc/meta.php"); ?&gt;
&lt;meta name="description" content="&lt;?php echo $description ?&gt;" /&gt;
&lt;meta name="keywords" content="&lt;?php echo keywords?&gt;" /&gt;
&lt;title&gt;&lt;?php echo $title ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="main"&gt;
&lt;?php include("$root/inc/header.php"); ?&gt;
&lt;?php include("$root/inc/nav.php"); ?&gt;
&lt;div&gt;&lt;?php echo $contents ?&gt;&lt;/div&gt;
&lt;?php include("$root/inc/footer.php"); ?&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;


example page.php

&lt;?php ob_start() ?&gt;
&lt;p&gt; main body html&lt;/p&gt;
&lt;?php
$title = "x"; 
$description = "x"; 
$keywords = "x"; 
$contents = ob_get_clean();
require 'layout_default.php'


This is a very crude implementation, simply enough to illustrate the principle.