Lab 2
/3680_S19/wk2/lab2.php
Your task is to create a webpage by embedding php in html. The script
page that you will be writing will contain ALL html tags within echo
statements. Everything about this webpage will be php output, for example:
<?php
// lab2.php
define('TITLE', 'lab2');
...
echo "<!DOCTYPE html>\n";
echo "<html lang=\"en\">\n";
echo " <head>\n";
echo " <title>".TITLE."</title>";
...
?>
Requirements
- Define 4 Constants: TITLE: title of page, CSS: rel path to file style.css,
DEVELOPER_MODE: true or 1, and LOGFILE: rel path and name of logfile
- After your defined constants, create an if statement at the top
of your script to control developer mode: error reporting, displaying
errors, and use your LOGFILE constant to set your error_log configuration.
- With a series of echo statments, start creating your page
like the example above. Use your TITLE and CSS constants when necessary.
- Create a fname variable and assign it the string value of your first name.
Within the body of the page, you will output in a h1 tag "Welcome to
fname's Lab 2".
- Write an if statement to see if fname is set, if so, error_log
that your fname variable has been set and show the value, else, error_log that
your fname variable hasn't been set.
- The external css file you will be writing can be simple, such that
styling a HTML table has equal cell dimensions, and is right text aligned.
Optionally, you may use Bootstrap for table style or a custom style of
your choice.
- After the heading of the page, you will create a 10x10 multiplication HTML
<table> [1..10]. Use a for loop to list the table headers from 1 to 10 .
Next use another for loop and a nested for loop to control the HTML
<tr>, <th scope='row'>, <td>, and calculation of the outter iterator value *
inner iterator value. Don't forget to close each data cell, row, and
the table.
- Create two variables, var1 and var2. Assign var1 to 1 and var2 to 2.
Output each calculation as a string, the calculated result and datatype
of the calculated result → gettype($res).
echo $var1." + ".$var2." is ".($var1+$var2)." (".gettype($var1+$var2).")";
echo $var1." . ".$var2." is ".($var1.$var2)." (".gettype($var1.$var2).")";
- Assign var1 to 1 and var2 to 2.0 (double)
Output each calculation as a string, the calculated result and datatype
of the calculated result.
- Assign var1 to string '1.0 word' and var2 to 2
Output each calculation as a string, the calculated result and datatype
of the calculated result.
- Assign var1 to string 'word' and var2 to 2.0
Output each calculation as a string, the calculated result and datatype
of the calculated result.
- echo a heredoc (<<<) paragraph for each: explain why an
int+double results as a double, why a string{starting with a numeric
value}+int results as a numeric value, and why a string+double results
as a double.
- Optionally, you may theme this webpage however you want.
Have the following assignment within your depository directory and your
public_html directory
/3680_S19/wk2/lab2.php