Pages

PHP inlude() Function

If some lines of code are to be included in every page of the website, The PHP include() funciotn works perfect.If you have been working in ASP.Net or in Dreamweaver than you must be familiar with the role of masterpages and frames in ASP.net and Dreamweaver respectively.Suppose if the look and feel of the website has to be kept similar than we can include the navigation and header files on every page using PHP include() function.

Consider these three files beneath.


Header.html

<html>
<head>
<title>Include Example</title>
</head>
<body>


Navigation.html

<ul>
<li><a href="home.html">Home</a></li>
<li><a href="products.html">Products</a></li>
<li><a href="Orders.html">Order</a></li>
<li><a href="contact.html">Contact Us</a></li>
<li><a href="about.html">About Us</a></li>
</ul>

Footer.html

</body>
</html>


All these three files above can be combined to form a single file with the help of PHP include() function.


Combined.php

<?php
include("header.html");
include("navigation.html");
include("footer.html");
?>


The purpose of PHP include() as explained in this example is not the only benefit of PHP include() function, large PHP scripts can be split up into many small PHP files than all these files may be included in a single file.This way the project is easy to understand and reusable.

 

0 comments:

Post a Comment