The Best Web Design Tips Blog
How to include files with PHP
The good news is that you don't have to be a pro in PHP to understand the functioning, usage and implementation of the PHP 'include' command. It's perhaps one of the advantages of PHP (no wonder, web designers' bank on this language!). What the 'include' command does is that it simply takes the filename and inserts the file into the script where the 'include' command is called.
Why use the 'include' command? Well, you could do the same thing without the 'include' command! The only difference would be that it would take few more pages, a lot more time, and more work than you ever want. Hoping that you are wise enough to make intelligent decisions, this topic is left as it is and we now move towards a practical example.
Create a NEW File(Navigation.php)
<a href=“http://www.xxx.com”>Link1</a>
<a href=“http://www.yyy.com”>Link2</a>
<a href=“http://www.zzz.com”>Link3</a>
Save the above code as say "Navigation.php". Now we will place this code in another file using the include command and thus save a lot of time, work and space.
Next we need to include the file we just created into our main design:
The Code
<html>
<body>
<?php include("Navigation.php"); ?>
</body>
</html>
So, this is how the 'include' files with PHP for your website template and spruce up your web site. Other files too can be stored and embedded in this fashion(e.g. Footer, banners, Navigation). When a file needs to be repeated many times, this technique can be employed to reduce the size of the code. An interesting thing is that since the 'include' file implies that the contents of the file included should be copied, in the source code the user gets to see the contents of the included file along with the main script. You can also include files only once by using 'include_once' instead of just 'include' although this usually requires more resources.
Link to This Page:
Archived Blogs
August 2008Google Enhanced 404 Pages How to Include Files with PHP Linking to an External CSS Stylesheet How to start a website
July 2008
1 Column Center Layout Creating an Optimized Navigation Google Indexing Flash
June 2008
SEO Cheatsheet FREE HTML File Optimizer
May 2008
Be Your Own Seo Pro HTML Form Validation Optimizing HTML Page Load Times 5 Reasons to validate your HTML