include()
module.
Later stages, to modify anything in that module, modify only in one location.Then automatically entire project gets updated.
require()
function is also used to include the file in php.
Include(): If any file doesn’t exist in the file structure, which is included in the code by using include function, then the control will go to the next statement and the execution will continue. It won’t stop the controller.
Require(): If the file doesn’t exist in the file structure, which is included in the code by using require function, then the control will terminate the flow of execution and gives an error. So when a file is mandatory only require function has to be used and properly checked, whether the file exist in the file structure of not.
menu.php
[php]
<?php
echo ‘<a href="/default.asp">Home</a> –
<a href="http://www.splessons.com/lesson/html-introduction/">HTML Tutorial</a> –
<a href="http://www.splessons.com/lesson/bootstrap-3-tutorial/">Bootstrap Tutorial</a> –
<a href="http://www.splessons.com/lesson/javascript-tutorial/">JavaScript Tutorial</a> –
<a href="http://www.splessons.com/lesson/php-tutorial/">PHP Tutorial</a>’;
?>
[/php]
include()
: abc.php
[php]
<html>
<body>
<div class="menu">
<?php include ‘menu.php’;?>
</div>
<h1>Welcome to SPLessons page!!</h1>
</body>
</html>
[/php]
Example: require()
[php]
<html>
<body>
<div class="menu">
<?php require ‘menu.php’;?>
</div>
echo "Welcome to SPLessons page!!";
</body>
</html>
[/php]
When above code is executed, when any error occurs, the echo statement will not be executed.