How to Build an HTML5 and CSS3 Page with PHP Includes - dummies

How to Build an HTML5 and CSS3 Page with PHP Includes

By Andy Harris

Of course, if you have access to PHP, it’s really quite easy to build HTML5 and CSS3 pages dynamically. Take a look at the csInclude.php program to see how this is done:

<!DOCTYPE html>
<html lang = "en-US">
 <head>
 <meta charset = "UTF-8">
 <title>CS PHP Includes</title>
 <link rel = "stylesheet"
   type = "text/css"
   href = "csStd.css" />
 </head>
 <body>
 <div id = "all">
  <!-- This div centers a fixed-width layout →
  <div id = "heading">
  <?php include("head.html"); ?>
  </div><!-- end heading div →
  <div id = "menu">
  <?php include("menu.html"); ?>
  </div> <!-- end menu div →
  <div class = "content">
  <?php include("story1.html"); ?>
  </div> <!-- end content div →
  <div class = "content">
  <?php include("story2.html"); ?>
  </div> <!-- end content div →
  <div id = "footer">
  <?php include("footer.html"); ?>
  </div> <!-- end footer div →
 </div> <!-- end all div →
 </body>
</html>

Using PHP is almost the same as using an SSI and AJAX approach:

  1. Start by building a template.

    The general template for all three styles of page inclusion is the same. There’s no need to change the general design or the CSS.

  2. Create a small PHP segment for each inclusion.

    In this particular situation, it’s easiest to write HTML code for the main site and write a small PHP section for each segment that needs to be included.

  3. Include the HTML file.

    Each PHP snippet does nothing more than include the appropriate HTML.