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 w3spoint.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 w3spoint.com |
<!DOCTYPE html> <html> <body> <h1>Welcome to my website!</h1> <p>Some more text.</p> <?php require 'footer.php'; ?> </body> </html> |