php include pages or files
require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.
- Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.
- It is possible to insert the content of one PHP file into another PHP file (before the server executes it), with the include or require statement.
- Including files saves a lot of work. This means that you can create a standard header, footer, or menu file for all your web pages. Then, when the header needs to be updated, you can only update the header include file.
How to use
PHP include Examples
Assume we have a standard footer file called “footer.php”, that looks like this:
echo “<p>Copyright © 2016-” . date(“Y”) . ” eduguru.in</p>”;
<html> <body> <h1>Welcome to my page. I am just testing how include page works!</h1> <p>We are just testing this.</p> <p>Now we have included as below.</p> <?php include 'footer.php';?> </body> </html>