Advertisement

Include and Require - Become No1 in php-10

Include and Require - Become No1 in php-10 You can include the content of a PHP file into another PHP file before the server executes it. You can create functions, headers, footers, or elements that can be reused on multiple pages.

There are two PHP functions which can be used to included one PHP file into another PHP file.

• The include() Function
The include() function takes all the text in a specified file and copies it into the file that uses the include function. If there is any problem in loading a file then the include() function generates a warning but the script will continue execution.

• The require() Function
The require() function takes all the text in a specified file and copies it into the file that uses the include function. If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script.

There is no difference in require() and include() except they handle error conditions. It is recommended to use the require() function instead of include(), because scripts should not continue executing if files are missing or misnamed.

This helps developers to make it easy to change the layout of complete website with minimal effort. If there is any change required then instead of changing thousand of files just change included file.
a. Include(“FileName.php”);
b. Require(“FileName.php”);
c. Require_once(“FileName.php”);
d. Include_once(“FileName.php”);

include_once will throw a warning, but will not stop PHP from executing the rest of the script.

require_once will throw an error and will stop PHP from executing the rest of the script.

Include php,Require php,

Post a Comment

0 Comments