Posted on May 25th, 2007
843 views A simple PHP includes tutorials
Hello guys and welcome to my first tutorial on pixel2life. This tutorial will be helpful to you who are learning PHP or just want an easy way to include files. The tutorial continues on the next page! Ok, so the code to include files are as follows: <?php include("filelocationhere") ?> It is a really simple way of including a file and is one of the most common pieces of code you will find in PHP. On the nextpage I will show you how you could use include files to make changing a webpage easier! If you use PHP includes, the page must have the .php extension rather then .html Ok so you have the basic HTML document:
Now, you can make that page a lot smaller by using PHP includes. This is how: Put everything above the "Your content here" line into a file called header.php. This is what should be in your header.php:
Now put everything below the "Your content here" line into a file called footer.php. This is what should be in your footer.php:
Now, you can change the basic HTML document to this:
If you have a really advanced template, this is makes it a lot easier to change your layout because you would update just the header.php & footer.php files and that would update all the pages. I hope you found this tutorial useful! Remember all pages using the include code must have the .php extension! |