Article Categories

Advertisement
Article Options
Your Favorite Articles
View All Favorites
Popular Articles
  1. Bold Text
  2. Simple Button
  3. Manage your MySpace Calendar
  4. How to add Photos to MySpace
  5. The Advantages of PHP
No popular articles found.
Popular Authors
  1. Adam Carmichael
  2. Joseph Lancaster
  3. Nicholas Hall
  4. Sanjib Ahmad
  5. Celeste Stewart
  6. Maneet Puri
  7. Deepaq Sharma
  8. Robby Alientjuh
  9. Anna Berk
  10. Arnab Ghosh
No popular authors found.
 »  Home  »  Web Development  »  PHP  »  Basic PHP includes
Basic PHP includes
By Alan Hettinger | Published  05/29/2006 | PHP | Rating:
Basic Includes
Lets say you have a Web site with 10 or so pages, and you want to update the navigation. You don't want the hassle of updating every single page. That's where includes come in handy.

Your basic include will look like this.

<?php include ( 'includes/navigation.php' ); ?>

That's it! What I typically do is design a page as usual, then begin breaking sections up into includes. To use this effectively:

1) Find sections or tables that will repeat throughout the site.
2) Cut the section of code out and paste it into another file.
3) Save this file into an includes folder.
4) Where the original section was, insert your PHP inclue code, referencing the file name.

Let's say I want to use the highlighted code on multiple pages.

<table>
<tr>
<td>
This table will be on every page.
</td>
</tr>
</table>

<table>
<tr>
<td>
This is some other content.
</td>
</tr>
</table>

I'll include it like this.

<?php include ( 'includes/table.php' ); ?>
<table>
<tr>
<td>
This is some other content.
</td>
</tr>
</table>

Now if I change table.php later, it will change on every page automatically. It's just like using image tags, but instead of image files, you are including pieces of html. This can save you hours and hours.

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Verification:
Enter the security code shown below:
img


Spread The Word

del.icio.us it Digg this Furl Reddit Yahoo! this!



Get updates in your E-mail - Get notified when new articles are added, and get exclusive offers from our partners!
E-mail Address:
Subscribe: UnSubscribe:
 
Related Articles