Ronald B Stamets Website Design and Development Corner of logo

Ronald B Stamets, Web Site Design and Development Services

top content bar
Home Website design Domains & Hosting E-Commerce Additional Services Contact Us About Us Web Design Tutorials FAQ Pay Bill Site Map Request Estimate

Break down your html and convert to PHP functions

Instead of all of the HTML code being physically on every page, we are going to get the HTML code from a single file by the use of 3 functions.  This is where we will begin converting HTML to PHP.

The diagram on the right shows what we want php to do for us on every page.

We will call the first function display_html_header(); This function will execute all of the code from the very top of your default.html file and stop at the end of the first table row.

The second function will execute all of the HTML code for the second row.. BUT ONLY TO THE END OF THE FIRST CELL.  We will name that function display_menu();

The third function, which we will call display_html_footer.  Will include the entire 3rd row of the table we created in default.html.

Notice that we excluded the second cell of row 2.  Since that cell contains our page content which is unique to each page, we will include the <TD></TD> for that cell on each page, but leave it empty so we can fill it with our beautiful unique information.

So our next step is to begin setting up the files to make our website easy to manage.


Open your text editor and create a new file and copy and past ALL of the code in blue into it.

<?php //Tell the server to parse this with php

//Tell the server to run this file

include_once("output_fns.php");

//Stop parsing php
?>

Name the file includes_fns.php and save it in your MYSITE folder.

Open your text editor and create another new file.

Name the file output_fns.php

Leave it blank but save it in your MYSITE folder.

You should now have these 4 items in your MYSITE folder.

Yours may look different, but the file names should match.

NOTE: I have learned that by using the _fns as a part of of the name of function files, it makes it easier to chase down code.  Only functions are written in function files.

The output_fns designation tells me that all of the functions within that file will be functions that display something. 

Other _fns files might be named forms_data_fns and might contain only validators to check the input of forms visitors fill out.


Previous Page Return To Main Index Next Page

:::Key Notes:::

Special PHP Tags:

// (This is the same for PHP as <!-- --> is for HTML except it is a single line comment).

/* */ (Is a multi-line comment in PHP. Everything in-between is commented).

***Unlike HTML comments, PHP comments do not display when the "view source" is used by a web browser.

<?php (Tells the server to start parsing PHP)

?> (Tells the server to stop parsing PHP


home
 
Website Design
 
Domains Hosting
 
ECommerce
 
addl services
   
Contact Us
 
About Us
 
Tutorials
 
Design FAQ
 
Pay Bill
 
site map