PHP: Main
In this tutorial you will be learning about the include function.
The include function is useful, if you have a common file that you want to use on a lot of pages.
Lets say you want to create some navigation links for your site, and use them on all of the pages of your site.
You could write out the HTML, and then copy it into every page, or you could use an unclude function.
This will save you a lot of time if you want to edit your navigation links, as you will only need to edit one file.
So for this example we will stick with the idea of navigation links.
First things first, create a page called navigation.html and in it, type out your links. Make sure you just type out the links, and dont put the <html> tags or <body> tags etc.
{a href="http://www.yoursite.com/index.php"}H
ome{/a}
{a href="http://www.yoursite.com/flash.php"}F
lash{/a}
{a href="http://www.yoursite.com/contact.php"
}Contact{/a}
Because of the BBS HTML formatting, you will need to replace { and } with < and >.
Now you have your navigation.html page with your links in.
Next go to index.php, and where you want the navigation links to be, put the following code:
<?php include("navigation.html"); ?>
Lets break the code down.
<?php - This tells the browser that where going to run a PHP script.
include("navigation.html"); - This tells the browser to display whatever data is in the file navigation.html.
?> - This closes the PHP script.
If you now check your index.php page, you should see your naigation links.
If you dont, it may be because you have placed the files in diferent directorys, or spelt something wrong.
The include function is a very simple, yet very effective peice of code.
Think of how much time you would have wasted if you had simply copied and pasted the navigation links into 30 pages, and then decided you wanted to add another link.
The include function allowd you to edit only 1 file, instead of 30.
Thats the end of the tutorial.
Im aware that its pretty simple, but people starting out with PHP will hopefully find it useful and time saving.
Any problems, tell me about them.
Brought to you by DannyIsOnFire.
www.dannyisonfire.com