Showing posts with label require and require_once. Show all posts
Showing posts with label require and require_once. Show all posts

Monday 28 September 2015

include , require and require_once , include_once in php

 include , require and require_once , include_once in php 


include, require and require_once,include_once are used to include a file into the PHP code

for example of include and require

<h1>Welcome to My blog!</h1>
<?php include 'header.php';
?>

it can added file in php code.

in require example

<h1>Welcome to My blog!</h1>
<?php require 'header.php';
?>

difference between  include and require

 when a file is included with the include statement and PHP cannot find it, the script will continue to execute

and

the echo statement will not be executed because the script execution dies after the require statement returned a fatal error

include_once 

It can be used include a PHP file another one, it can used to add files once. If it is found that the file has already been included, calling script is going to ignore further inclusions.

Syntax



include_once('name of the called file with path');

example 

<?php include_once('xyz.php'); 

?>

same as require_once used.

<?php require_once('example.php')  ?>

include_once and require_once same different with include and require.