> Online tutorial : include in php
Showing posts with label include in php. Show all posts
Showing posts with label include in php. Show all posts

require in php

The require() function is identical to include() except that is handle error differently.
The the function include() generates a warning(but the script continue execution) while the require() function generates a fatal error (and script stop)
Syntax
include "function name";
Example
vars.php


<?php
$color='red';
$fruit='apple';
echo $fruit."color is".$color"
?>
test.php

<?php
echo "a $color $fruit"
// include 'vars.php
require'vars.php'
echo "a $color $fruit"
?>
Output:



include_once in php

The include_once()statement include and evaluates the specified file during of execution of the script.This is a behavior similar to the include() function with the only difference being that it code from a file has already been included.It will not be included again.

Syntax
include "function name";
Example
vars.php


<?php
$color='red';
$fruit='apple';
echo $fruit."color is".$color"
?>
test.php

<?php
echo "a $color $fruit"
// include 'vars.php
include_once'vars.php'
echo "a $color $fruit"
?>
Output:

include in php

The include() function takes all the text in a specified file and copies it into file that used the include function
Syntax
include "function name";
Example
vars.php


<?php
$color='red';
$fruit='apple';
echo $fruit."color is".$color"
?>
test.php

<?php
echo "a $color $fruit"
// include 'vars.php
include 'vars.php'
echo "a $color $fruit"
?>
Output: