Break down your html and convert to PHP functionsInstead 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
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.
|