To include the content of a PHP file into another PHP file before the server executes it. There are three PHP functions which can be used to include one PHP file into another PHP file.
- The include() Function
- The require() Function
- The require_once() Function
The include() Function
The include() function copies all text from file which is passed as parameter into the file that uses the include function. If there is any problem in loading thefile then the include() function generates a warning but the script will continue execution.Usuage of include function :
Below is code of my main file .
<?php include("one.php"); ?> |
Here the code of one.php will be copied to main file.
The require() Function
The require() function copies all text from file which is passed as parameter into the file that uses the include function. If there is any problem in loading the file then the require() function generates a fatal error and halt the execution of the script.Usuage of require function :
Below is code of my main file .
<?php include("two.php"); ?> |
Here the code of two.php will be copied to main file.
The main difference in require() and include() is the way of handling error conditions. It is recommended to use the require() function instead of include(), because scripts should not continue executing if there is some issue in file loading.
No comments:
Post a Comment