Aims:
header
and footer
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>...</title> <link rel="stylesheet" href="…" /> </head> <body> <h1>…</h1>
<footer> <small> © 2013 National University of Nerdland </small> </footer> </body> </html>
output_header
output_footer
output_functions.php
.html
).php
)require_once
to load the file of functions
output_header
function
output_footer
function
output_header
functionfunction output_header( $title, $stylesheet ) { echo '<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" />'; echo "<title>{$title}</title>"; echo "<link rel=\"stylesheet\" href=\"{$stylesheet}\" />"; echo '</head> <body>'; echo "<h1>{$title}</h1>"; }
alchemy.php
<?php require_once('output_functions.php'); output_header( 'Department of Alchemy', 'nerdland.css' ); ?> <p> Welcome to the Department of Alchemy at the National University of Nerdland! We're great, we are. </p> <?php output_footer( 'National University of Nerdland' ); ?>
output_functions.php
file to turn it into
a useful 'library'
output_paragraph
(see earlier lecture)
output_submit_button
to
echo submit buttons for when the programmer is producing a form
(see next slide)
output_reset_button
that will echo reset buttons
output_textfield
that will echo text fields. Your function could have the following
prototype:
void output_textfield( $id, $label, $name, $size, $maxlength, $value, $is_disabled )
output_unordered_list
,…
output_submit_button
functionfunction output_submit_button( $button_label ) { echo "<input type=\"submit\" name=\"submit\" value=\"{$button_label}\" />"; }
pockets.php
, the new version of pockets.html
<?php require_once('output_functions.php'); output_header( "What's in your pocket?", 'pockets.css' ); ?> <form action="process.php" method="get"> <?php output_textfield('firstname', 'Firstname: ', 'firstname', 25, 25, '', false); output_textfield('surname', 'Surname: ', 'surname', 25, 25, '', false); output_textfield('num_1c_coins', 'One cents: ', 'num_1c_coins', 3, 3, '0', false); output_textfield('num_2c_coins', 'Two cents: ', 'num_2c_coins', 3, 3, '0', false); … output_textfield('num_50e_notes', 'Fifty euros: ', 'num_50e_notes', 3, 3, '0', false); output_submit_button('Compute'); output_reset_button('CLEAR'); ?> </form> <?php output_footer('University College Cork'); ?>
include
, include_once
and require
as alternatives to require_once