The Include Function
Without understanding much about the details of PHP, you can save yourself 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.
Why is this a cool thing? Well, first of all, 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.
-----------------------------------------------------------------------------------
An Include Example
Say we wanted to create 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. Since we want to create a common menu, let us save it as "menu.inc".
-----------------
Save the above file as "menu.inc". Now create a new file, "index.php" in the same directory as "menu.inc". Here we will take advantage of the include function to add our common menu.
[/code]
Without understanding much about the details of PHP, you can save yourself 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.
Why is this a cool thing? Well, first of all, 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.
-----------------------------------------------------------------------------------
An Include Example
Say we wanted to create 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. Since we want to create a common menu, let us save it as "menu.inc".
-----------------
| Code: |
|
menu.inc Code: <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 /> |
Save the above file as "menu.inc". Now create a new file, "index.php" in the same directory as "menu.inc". Here we will take advantage of the include function to add our common menu.
| Code: |
|
index.php Code: <?php include("menu.inc"); ?> <p>This is my home page that uses a common menu to save me time when I add new pages to my website!</p> </body> </html> |
[/code]
