PHP allows to use one PHP or HTML file into other PHP files, it has following advantages
- Code reusability
- Easy error finding and debugging
- Large project can be managed easily.
- No code repetition or duplicacy.
To re-use files, PHP provides two functions.
- include
- require
include
It includes a given PHP or HTML file into another PHP file. If file is not found, it continues execution of PHP script with E_WARNING.
Syntax
include 'filename.php';
or
include('filename.php');
Example
<?php
include('math.php');
?>
require
It works same as include but it stops execution if file is not found with fatal error E_COMPILE_ERROR
Syntax
require 'filename.php';
or
require('filename.php');
Example
<?php
require('math.php');
?>