-
The include and require statement takes all the text, code that in the particular file, and copies it into the file by using the include and
require statement.
- PHP include and require include PHP,HTMl, or text on multiple pages.
-
PHP include and require Statements is used to insert the content of one PHP file into another PHP file (before the server executes it), with
the include or require statement.
- Syntax
include 'filename';
OR
include_once 'filename';
- Example-1
- Main.php file code
<html>
<body>
<p>Main file content</p>
<?php
include 'include_file.php';
?>
</body>
</html>
- include_file.php file code
<?php
echo "<p>Include file content</p>";
?>
Output:
Main file content
Include file content
- Example-2
- Main.php file code using include_once()
<html>
<body>
<?php
include_once 'include_file.php';
echo "Main File content :- Welcome to $name.";
?>
</body>
</html>
- include_file.php file code
<?php
$name='PHPCodersPoint';
?>
Output:
Main File content :- Welcome to PHPCodersPoint.