Use of Including files.
- Including multiple PHP files helps Maintainability
- Huge blocks of code can be split into small useful blocks which can be included wherever necessary.
- Re-usability of code.
How To
- Using Require.
- Produces a fatal-error (E_COMPILE_ERROR) and stops the script if the Code fails to load the Script file.
- Using Include.
- Produces a warning (E_WARNING) and Resumes the script upon failure.
Syntax :
<?php include 'script_name.php ' ?>
<?php require 'script_name.php' ?>
Example
<!-- test.php -->
echo " Hello World <br/>" ;
echo "This Message is Displayed by the Included file test.php <br/> " ;
<!-- Main.php -->
<?php
echo "This is Displayed from main.php <br/>";
include "test.php";
?>
Output
This is Displayed from main.php
Hello World
This message is Displayed from Test.php
Hello World
This message is Displayed from Test.php
For more Information refer
No comments:
Post a Comment