What's the code used in HTML for a PHP include file?
The code used in HTML to reference a PHP include file is as follows:
<?php include("file.inc"); ?>
Include files are used for various purposes. A very common use of include files is for creating a website's header and footer. This allows the ability to make sitewide changes to design or navigation by simply changing one or two include files rather than having to update every individual page of a website.
Steps to create an include file for a header or footer PHP include:
Step 1 - Design your website template in HTML and make a backup (call it template.html). Then make a copy of your template.html page and rename the file extension from .html to template.php - If you have never changed file extension before read instructions to change file extensions in Windows.
Step 2 - Next, create a text file called header.txt and footer.txt and change both file extension to .inc so that now you will have header.inc and footer.inc
Step 3 - Going back to your template.php file, copy only the portion of the HTML source code you would like as your header. Generally it will be a portion of HTML just after the <BODY> tag of your document and might contain your top banner and navigation depending on how much you want the includes to handle. Once you have copied this HTML simply paste it within your header.inc and save the include file. Note: You can use comment tags as placemarkers in the HTML so that you have a guide to where you copy/cut code, e.g. <!--header start--> and <!--header end-->.
Step 4 - Go back to your template.php file and delete the code you already placed inside your header.inc file. You will now replace that deleted section of HTML code with the following... <?php include("header.inc"); ?> . If you used comment tags in the previous step then this tends to be a lot easier. That's it!
Step 5 - Repeat the same process (steps 1 through 4) for your footer but using <?php include("footer.inc"); ?>
Step 6 - Test your page by uploading it to a php enabled server. Make sure your template.php file is in the same directory with your header.inc and footer.inc