PHP include
Published on: 2005-08-14 - Views: 10414
PHP include function is one of the most used in php web programming.
It lets you recall another page/snippet so you can use it as it was in the current page.
Web developers use it really much and it lets them save a lot of time, as, once you need to update something that is show on all your pages, you simply have to edit the content of the included file, and not of all the pages, you you can have your change running in 1 second instead of modifing 10s or 100s pages.
For example we use it to include in each page our left menu and lots of other stuff.
Let's have a deep look at PHP include: we'll make 2 files now, one is the included file and one is the includer.
File included.txt
Open a new blank file with your text editor ( Notepad is good) and type something into it; our content is:
This is the text that shows up, it comes from the included file.
File includer.php
<html>
<body>
This page is about blah blah blah...
<?php include 'included.txt'; ?>
</body> </html>
Your output will be:
<body>
This page is about blah blah blah...
<?php include 'included.txt'; ?>
</body> </html>
This page is about blah blah blah...
This is the text that shows up, it comes from the included file.
It doesn't look so exciting in this way...but in place of the txt file you could recall some html code or a php script that serves your ad banners, shows site statistics, runs MySQL queries or everything else that comes to your mind.This is the text that shows up, it comes from the included file.


