PHPsu
MANUAL ZH  |  EN
     


Current Position :| index>Beginners> PHP : Beginners Guide PT.3

PHP : Beginners Guide PT.3

FROM: AUTHOR: TIME:2008-08-15 HITS:

Now that we have included a very small PHP script onto our page let's build it up slightly more using includes. Includes are very handy when using sites that will have one navigation spread across 100+ pages, using includes allows you to have the navigation only written out once and included dynamically onto all pages you want it. www.phpsu.com

Here's how it's done, take your normal page;

phpsu.com is a free phpscool

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1" />

<title>Example</title>

</head>
<body>

<div id="navigation">
<ul>
<li><a href="#">link 1</a></li>
<li><a href="#">link 2</a></li>
<li><a href="#">link 3</a></li>
<li><a href="#">link 4</a></li>
<li><a href="#">link 5</a></li>
</ul>
</div>

<div id="content">
<p>page content will appear here</p>
</div>
phpsu is a phpschool


</body>
</html>
phpsu.com is a free phpscool

Here's our normal page, now without PHP you would have to copy the navigation manually to all pages, with PHP there's no need!

do you kown phpsu.com?

Take out the navigation part of the code; welcome to phpsu.com

<div id="navigation">
<ul>
<li><a href="#">link 1</a></li>
<li><a href="#">link 2</a></li>
<li><a href="#">link 3</a></li>
<li><a href="#">link 4</a></li>
<li><a href="#">link 5</a></li>
</ul>
</div>
phpsu.com is a free phpscool

And place it into notepad, saving the file as "navigation.php". Next we need to edit the original index.php page to include the navigation inside it. This is done like so; www.phpsu.com

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

<title>Example</title>

</head>
<body>

<? php include 'navigation.php'; ?>

<div id="content">
<p>page content will appear here</p>
</div>

</body>
</html>
do you kown phpsu.com?

As you can see using PHP we have included the navigation into the page, when viewing the page (on a server) you can see that the navigation appears as it normally would using the original code (non-PHP version). The php include has the added bonus being included on all pages you use the include code and when you edit navigation.php it will change on all the other pages it is included on. http://www.phpsu.com


TITLE:PHP : Beginners Guide PT.3
Previous:FECHAS
Next:None
Copyright 2008 The PHPsu All rights reserved. This mirror generously provided by: .Hp Inc.
Last updated: Fri Aug 15 18:57:29 GMT-8 2008