CSE3MS Lab 2 - Introductory PHP

The second laboratory is devoted to building competence with basic PHP scripting and developing dynamic documents. Because PHP has only been enabled on the team accounts you need to log onto your team account to do this lab.

Exercise 1

Create a document hello-world.php in the web/htdocs/<your-username>/ directory in your team account. Make this file world (or other) readable. Then create a link to this new document from the simple index.html you created last week. The difference between your PHP page and the index page being that you place a simple php echo statement into the PHP document to display "Hello World".

Example:

Hello World

Exercise 2

Next modify the "hello world" file so that "Hello World" is printed out multiple times. Do this by using the PHP for loop construct.

Example:

Hello World
Hello World
Hello World

Exercise 3

Modify the file again so that the "Hello World" line are printed in an alternating choice of font. The font can be bolded/colored/italicised or anything else that you want to choose. See the example below.

Example:

Hello World
Hello World
Hello World
Hello World
Hello World

Exercise 4

Modify the file again so that the number of times that the "Hello World" to be printed will be held in a variable. Now create a plain html file that contains a form who's action is the php file. The plain html form should have an input in which you can enter a number that specifies the number of times that the "Hello World" line should be printed out.

HINT:To do this the variable name must be the same as the name of the input element in the form.

Exercise 5

Modify the above form and php file so that the form accepts a second input which is the name of a person who is to be greeted. Adapt the php script file so that the greeting can be modified by input. If the user enters 5 and Bob as the input data to the form name then "Hello Bob" will output 5 times with each second line in the different color/font.

Example:

Hello Bob
Hello Bob
Hello Bob
Hello Bob
Hello Bob

Exercise 5

Finally adjust the php script file again so that the output is placed in a table. The table should have 2 columns. The first column having holds a line number and the second one the greeting.

Example:

1Hello Bob
2Hello Bob
3Hello Bob
4Hello Bob
5Hello Bob