Well, this is quite a broad subject that a simple search can give you alot of tutorials on. Most people use frameworks that are built for using templates, such as a content management system (PHPBB and WordPress come to mind).
Here's a most basic 'technically' a template format.
header.phpCODE
<h1>I am the header, hear me roar!</h1>
footer.phpCODE
<p>I'm the footer, at the end of the page</p>
page.phpCODE
<?php include('header.php'); ?>
<p>This is my page, and I can alter it how I want. The header and footer are independent and can be altered separately, and will not have to be changed on every single page of the site!</p>
<?php include('footer.php'); ?>
page2.phpCODE
<?php include('header.php'); ?>
<p>See I'm a second page, and changing the header or footer will reflect a change on me too! You won't have to manually edit my header or footer on every page because you changed it from one location that I am pulling it from!</p>
<?php include('footer.php'); ?>
Basically that's all that really happens, but full on template systems have options for parsing certain tags and adding your own things to them. Take a look at PHPBB's template system and feel free to be amazed at its complexity. Or any forum software really.