We are constantly accelerating upwards and outwards from the Earth. I know, I can feel it.” Anon
justfigures

a niche content web resource for geeks

       

Search Amazon

Your requested tutorial is PHP: Intro snippet 1.

 

Calling an include file.

 

Back to PHP: Intro


Calling an include file is probably the most common and popular reason for incorporating PHP within a website design strategy. The PHP include() function provides the ability to change the content of multiple PHP web page files across a website with the minimum of effort.

 

Method:

 

Place the content that is to be repeated across multiple web pages within a single file. This file normally has a .inc file extension but .txt or .php file extensions are also used.

 

Example: Let's create a file called 'commonStatement.inc' and place in this the text, 'a code snippet library for website developers'.

 

Add the include() function to your PHP web page, see code snippet below, at a point wherever the content is to be inserted in the page.

 

Changing the content of the .inc include file will automatically change the content of the multiple web pages that contain the include() function.

 

Place the following PHP code snippet in the PHP web page to call the content of the include file.


Highlight the snippet and copy to place onto clipboard.




PHP:Intro snippet 1

Calling an include file

Place the following PHP code snippet in the web page to call the content of the include file

<?php
include("commonStatement.inc");
?>
	

 

The content of 'commonStatement.inc' will appear at the point the include() function is called within the PHP web page.

 

Note: The content of the incude file can be XHTML (HTML) code markup. Simply place the XHTML code into the include file as you would wish the XHTML to be written to the web page.

 

This can be a time saver for creating a common navigation bar that will grow and change when new pages are added to the website. Simply change the markup in the include file for the new pages to be accessibly from all the other pages on the website.

 

Back to top

 

Bookmark and Share

 

Copyright © 2006-2010 justfigures.co.uk