You can include the PHP, Html, or content on multiple pages with the help of PHP including files. There are two PHP functions that can be used to include one file into another file.
PHP include and require Statements
- Theinclude() Function
- Therequire() Function
The include and require statements are applied to include useful codes written in other files.
These are the most important PHP functions because its reused on multiple pages. This will help designers to make it easy to modify the design of the entire website with less effort.
If you want to any change in multiple files, you can just change single included file instead of changing thousand of files.
- require() function will generate a fatal error (E_COMPILE_ERROR) and the script will stop.
- include() function will only generate a warning (E_WARNING) and the statement will continue.
Syntax
include 'filename'; or require 'filename';
PHP include Examples
In this example we will include header file in a page using include statement:
<html> <body> <h1>Welcome to contact page!</h1> <p>here are some text.</p> <?php include 'header.php';?> </body> </html>