| Home / Technology / Web_development / Php | |
![]() |
PHP: Including FilesFile includes are a way for web programmers to create a section of code that will be used on multiple web pages, save it in a separate file, and then tell each individual page to go add that code before being shipped out to the user's browser. These are great for maintaining code for menu bars and for address information at the bottom of a page. To create a file include, create your section of regular code then save it in a separate file. The file can be any portion of code you want to have inserted on your web page, and may even contain php scripts inside of it. When you are finished, save the snippet as a separate file. To identify the file as an include section, you may save it with an INC extension, such as file.inc.
To use this section of code on the web page, use the "include" command in php:
<?php include "file.inc"?>
Example:
1. We type a portion of code in its own separate file:
2.Save the code as menu.inc.
3.On our page, use the include function to insert the menu where we want it.
4. Save the web page as a .php file, and when the page is displayed, the menu will be included right before the sentence. |