CodesJava

Easy learning with example program codes

PHP Include require


PHP Include:

Including a file in PHP means reusing the files many a times. For this, PHP facilitates two ways:

  • PHP include
  • PHP require

These methods are used to reuse HTML and PHP scripts in more than one PHP scripts.

Comparison between PHP Include and PHP Require:

PHP Include PHP Require
It is used to include files on the basis of their path. It is also used to include files on the basis of their path.
Both relative and absolute path of the file can be used. Both relative and absolute path of the file can be used.
PHP include allows the script to continue, even if file is missing or inclusion fails in any condition. PHP require halts the script, if a file is missing or inclusion fails in any condition, producing a fatal E_COMPILE_ERROR level error.

Example 1
footer.php

Copyright © 2018 codesjava.com
<!DOCTYPE html>
<html>
<body>
 
<h1>Welcome to Codesjava!</h1>
 
<p>Some more text.</p>
<?php 
include 'footer.php';
?>
 
</body>
</html>

Example 2
footer.php

Copyright © 2018 codesjava.com
<!DOCTYPE html>
<html>
<body>
 
<h1>Welcome to my website!</h1>
 
<p>Some more text.</p>
<?php 
require 'footer.php';
?>
 
</body>
</html>
Posted in PHP   
Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki