PHP include file - The php include function
In this tutorial I will show you how to divide your code into more files and how to include various files into your actual PHP code.
|Name:||PHP include file|
Bookmark PHP include file
Step 2 - The php include function
PHP include file
The first way to include a file is using the include function. This is a PHP built in code and the synatx is the following:
include ( filename )
This code tries to include the content of the file defined by filename. If the file doesn't exists the include function will report a warning but the script will continue.
Let's see an example. First we create a file which will be included later and it only contains a variable initialisation:
- $i = 100;
Output:Value of i before include is: --
Value of i after include is: -100-
Without the include function the code would be something like this:
Previous Step of PHP include fileNext Step of PHP include file
Tags: php incluude file, php include, include file, file include, php, include, file