PHP Programing language

adplus-dvertising
PHP Include
Previous Home Next

In this PHP , Without understanding much about the details of PHP, and we can saving a great deal of time with the use of the PHP include function. The include function takes a file name and simply inserts that files contents into the file that calls the include function.

In PHP include for file so, this means that you can type up a common header or menu file that you want all your web pages to include. When you add a new page to your site, instead of having to update the links on tens of separate web pages, you can simply change the Menu file.

Example:

To creating a common menu file that all our pages will use. For easy reference, files that are to be included usually are named with a ".inc" extension.

<html> <body>
<a href="index.php">Home</a>
<a href="about.php">About Us</a>
<a href="links.php">Resources</a>
<a href="contact.php">Contact Us</a> <br />

To Save the above file as "minu.inc". and again creating a new file for "index.php" in the same directory as "minu.inc". Here we will take advantage of the include function to add our common menu.

index.php Code:

<?php 
include("menu.inc"); ?>
<p>this is my favourite site 
it's more valuable site the name of this site is r4rtechsoft</p>
</body>
</html>

And we would do the same thing for "about.php", "links.php", and "contact.php". Just think how terrible it would be if you had 15 or more pages with a common menu and you decided to add another web page to that site. Avoid such troublesome occasions with a simple include file.

What do Visitor's See?

If we were to use the include function to include a common menu on each of our web pages, what would the visitor see if they viewed the source, of "index.php". Well because the include function is pretty much the same as a copy and paste of the text, the visitors would see:

View Source of index.php to a Visitor:

<html> <body>
<a href="index.php">Home</a>
<a href="about.php">About Us</a> 
<a href="links.php">Links</a>
<a href="contact.php">Contact Us</a> <br /> 
<p>this is my favourite site it's more valuable site the name of this site is r4rtechsoft</p>
</body>
</html>
Previous Home Next