PHP Tutorial > INCLUDE
INCLUDE is used in PHP to append the code from an external file into the current file. The syntax for INCLUDE is
INCLUDE ("external_file_name");
This is a convenient feature for a large website. Often, we may want to change an element of the website that is consistent across the entire site, yet we don't want to go through the trouble of updating every single file. In this case, we can simply use INCLUDE in every file to call the same external file, and then all we need to change is the content in that one external file.
Let's look at a simple example. Assuming we have the following two files:
index.php
|
<?php
print "This is the original content<br>";
include ("external_file");
?>
|
external_file
|
<?php
print "This is the external content";
?>
|
Upon executing index.php, we'll get the following output:
|
This is the original content
This is the external content
|
This is because, to the web server, it sees the following content:
|
<?php
print "This is the original content<br>";
print "This is the external content";
?>
|
Next: PHP Functions
Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.
Copyright 2007-2009 1keydata.com All Rights Reserved. Privacy Policy
|