PHP is a programming/scripting language designed to run on a web server. It
can also be used at the command line. This tutorial concentrates on command
line examples for complete beginners. All the examples below assume you
are using a Windows computer or network.
Lesson |
Example Program |
Homework |
One |
"Hello World!" and Setting up the Working
Environment |
- Write a more complex version of this program to display several lines
of text and get control of the text layout by using space characters.
|
Two |
Text Input and Output |
- Extend the program to hold a longer conversation. Use more variables.
|
Three |
Arithmetic |
- Write more programs to add, subtract, multiply and divide. Try dividing
by zero.
|
Four |
The IF Statement
Data validation and the divide by zero problem. |
- Write a program which prompts for your name and a number representing
the hour of the day. The number will be between 0 and 23. Depending
on the time of day, your program shoud reply with
- Good morning {name}
- Good afternoon {name}
- Good evening {name}
- Good night {name}
Numbers below zero and above 23 should be rejected. |
Four (b) |
Determine the Type of Input Data |
- (b) Write a program that
- performs addition if you type in two numbers.
- joins the text if you type in two text strings.
- joins the text if you type in one text string and one number (it must
treat the number as text).
|
Five |
The For Loop |
- Display text like this using FOR loops to control the layout.
* *
* *
* *
**
**
* *
* *
* *
|
Six |
Functions |
- Write a program using functions to return a line of text underlined
with "-" signs.
|
Seven |
The While Loop |
- Write a program using a while loop and an if
statement to act as a menu. The menu choices should be insert,
edit, delete and quit.
Write three functions named, insert, edit and delete. These are stub
functions. They will not actually work but they act as place holders
so you can set up the program structure.
The functions should echo text to show they are working. Suitable text
would be "Insert", "Edit" and "Delete".
|
Eight |
The Do Loop |
- (a) Write a program to calculate the average of the input numbers.
Use zero to terminate the program.
- (b) Draw a structure diagram of your program.
|
Nine |
Control Structures Summary |
- Learn the control structures and operators regularly used in PHP programming.
|
Ten |
Simple Arrays |
- Write a program to prompt for numbers which will be stored into an
array. The program should then display a bar chart (made out of text
characters) using the data stored in the array.
|
Eleven |
Using classes |
- Extend this example to store and display a full name and address record.
|
Twelve |
Implement a Menu |
- Add stub (non working) choices to the menu to provide save
and load choices. The code needed for these choices
is in the next example. The word "Save" or "Load"
should be displayed to show that your menu choices are working.
|
Thirteen |
File Input/Output |
- Modify your work from lesson twelve. You should already have added
"load" and "save" stub functions. (non working functions).
Get load and save to work properly.
|
Fourteen |
Factorial N |
- Find other examples of recursive functions. Implement one of them.
|
Fifteen |
Mini Project |
- Design, write and document a complete program. It should
- Manage a list of names and addresses
- Use a class to store the names and addresses
- Store the class objects in an array
- Provide menu choices to quit, add, delete, load, save, select previous
and select next record.
|
Where Next? |
Using PHP inside web pages. |
Here is the PHP in web pages tutorial. |