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

require_once in php

The require_once()statement include and evaluates the specified file during of execution of the script.This is a behavior similar to the require() 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
require_once'vars.php'
echo "a $color $fruit"
?>
Output:



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: