PHP Include Files Tutorial Print

  • 82

Including other files in your PHP code is a common task. If you look at the big PHP frameworks and applications out there like CakePHP and Joomla!, you’ll notice lots of ‘include()’ statements.

The include statement tells the PHP parser to insert the content of a file directly in the location you have specified in the current PHP file.

For example, let’s say you have a footer.php file located in your root directory that runs some PHP code and you want to show that in your index.php file.

In your index.php file, you simply need to write the following statement wherever you want the footer.php code to be executed (in this case, probably at the bottom of the file) :

<?php
include(“/footer.php”);
?>

Was this answer helpful?

« Back