saftutorials.com
PHP INCLUDE Tutorial

By using these PHP function you can include one PHP file content to another PHP file before the server executes the code. There is two PHP function by which you can include. Those function built in default by PHP. 

How many function include in PHP?
These are two PHP function by which you can include.
include() function
require() function

By using these function you can divide a thousands line of code of PHP file into multiple PHP files in the minimum line of code.

By this, you can easily understand the code.


PHP include() function

PHP include() function copy all lines of code from a specified file and paste it into the file that uses the include() function.

If there is any problem while loading the included page then include function generates a warning but code execution will continue.

Example of PHP include() function.

This is the header.php page

<a href="home.php">Home</a> -
<a href="learn_html.php">HTML Tutorial</a> -
<a href="learn_css.php">CSS Tutorial</a> -
<a href="learn_js.php">JavaScript Tutorial</a> -
<a href="learn_php.php">PHP Tutorial</a>


This is another page home.php where we include header.php page by using the include function

<!DOCTYPE html>
<html>
<body>
<?php include 'header.php';?>
<h1>The is home page</h1>
</body>
</html>


PHP require() function

PHP require() function copy all lines of code from a specified file and paste it into the file that uses the require() function.

If there is any problem while loading the included page then require function generates fatal error and code execution will be stopped.


Example of PHP require function


This is the header.php page

<a href="home.php">Home</a> -
<a href="learn_html.php">HTML Tutorial</a> -
<a href="learn_css.php">CSS Tutorial</a> -
<a href="learn_js.php">JavaScript Tutorial</a> -
<a href="learn_php.php">PHP Tutorial</a>


This is the footer.php page

<a href="http://www.saftutorials.com/">Designed & Developed by SAF Tutorials</a> -
<a href="#">All Rights Reserved</a>


This is another page home.php, where we include header.php and footer.php page by using, require function

<!DOCTYPE html>
<html>
<body>
<?php include 'header.php';?>
<h1>The is home page</h1>
<?php include 'footer.php';?>
</body>
</html>

Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic