View Single Post
Old Oct 30th, 2005, 12:07 AM   #7
Mocker
Hobbyist Programmer
 
Mocker's Avatar
 
Join Date: Oct 2005
Location: Indiana
Posts: 224
Rep Power: 0 Mocker is an unknown quantity at this point
Send a message via AIM to Mocker
Quote:
Originally Posted by jstephens
So can you place your functions into a seperate page and use an include? All the examples in the book show poor usage of them. I am looking for an actual real world Example of how and when to use them. One of the examples in the book is as follows:

function page_Header($color) {
print "<html><head><title>Welcome to My Site </title></head>";
print "<body bgcolor = " . ' $color ' . ">";
}

This is typed into the same web page as the call to the function. So how would I use this over again.

It might be simplified, but say you make one php program to serve up lots of websites (ie index.php?page=home index.php?page=gallery index.php?page=login)

You are going to be duplicating a lot of html output, so you would want all the html that is going to be the same in every page to be in its own function, or set of functions. So everytime you make a webpage you can call

page_Header();
if($_GET['page']){
//decide what content to show based upon the page
}
page_Footer();

this is really basic, but the point is there is a reason the header was put in its own function. You want to keep the different parts of your program defined.
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi
freelance scripts - http://ryanguthrie.com/index.html
Mocker is offline   Reply With Quote