Home

How to Build an HTML5 and CSS3 Page with PHP Includes

|
Updated:  
2016-03-26 13:13:11
|
HTML5 and CSS3 All-in-One For Dummies
Explore Book
Buy On Amazon

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.

About This Article

This article is from the book: 

About the book author:

Andy Harris earned a degree in Special Education from Indiana University/Purdue University–Indianapolis (IUPUI). He taught young adults with severe disabilities for several years. He also taught himself enough computer programming to support his teaching habit with freelance programming.
Those were the exciting days when computers started to have hard drives, and some computers connected to each other with arcane protocols. He taught programming in those days because it was fun.
Eventually, Andy decided to teach computer science full time, and he still teaches at IUPUI. He lectures in the applied computing program and runs the streaming media lab. He also teaches classes in whatever programming language is in demand at the time. He has developed a large number of online video-based courses and international distance education projects.
Andy has written several books on various computing topics and languages including Java, C#, mobile computing, JavaScript, and PHP/MySQL.
Andy welcomes comments and suggestions about his books. He can be reached at [email protected].