php include pages or files

5 (100%) 2 votes

php include pages or files

The include (or 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

include ‘filename‘;

or

require ‘filename‘;

PHP include Examples

Assume we have a standard footer file called “footer.php”, that looks like this:

footer.php
<?php
echo “<p>Copyright &copy; 2016-” . date(“Y”) . ” eduguru.in</p>”;
?>
index.php
<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>

 

 

For any query or issue, feel free to discuss on http://discuss.eduguru.in
%d bloggers like this: