In PHP, the content of another file is used in one file. For this, PHP has given two functions.
- Include() Function.
- Required() Fucntion.
1.Include() Function
The include () function uses the external php file in a php file. The external php file to include in the include function has to be written with the path to the name of the file. The path is written in double ("") or single quotes (''). Syntax<?php include("csharpcorner.php"); ?>
other_file.php
Source Code :<?php echo "other file name is Experts PHP."; ?>
Example for include() function
my_file.php
Source Code : <?php echo "my file name is Experts"; include ("other_file.php"); ?>Output :
my file name is Experts other file name is Experts PHP.
2.Required() Fucntion.
The require () function is similar to the include () function.<?php require("other_file.php"); ?>
other_file.php
Source Code :<?php echo "other file name is Experts PHP."; ?>
Example for require() function
my_file.php
Source Code : <?php echo "my file name is Experts"; require ("other_file.php"); ?>Output :
my file name is Experts other file name is Experts PHP.