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.