INTRODUCTION

Site Home
LAMP Home
PHP Console Home
Getting Started
PHP Reference
Download Tutorial

LESSONS

01 Hello World!
02 Text I/O
03 Arithmetic
04 IF Statement
04 (b) Data Types
05 FOR Loop
06 Functions
07 While Loop
08 Do Loop
09 PHP Reference
10 Array
11 Classes
12 Menu
13 File I/O
14 Factorial N

MORE PHP

PHP in web pages
PHP and MySQL

PHP Tutorial for Complete Beginners

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

  1. 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

  1. Extend the program to hold a longer conversation. Use more variables.

Three

Arithmetic

  1. 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.

  1. 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

  1. (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

  1. Display text like this using FOR loops to control the layout.
 *      *
  *    *
   *  *
    **
    **
   *  *
  *    *
 *      *

Six

Functions

  1. Write a program using functions to return a line of text underlined with "-" signs.

Seven

The While Loop

  1. 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

  1. (a) Write a program to calculate the average of the input numbers. Use zero to terminate the program.
  1. (b) Draw a structure diagram of your program.

Nine

Control Structures Summary

  1. Learn the control structures and operators regularly used in PHP programming.

Ten

Simple Arrays

  1. 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

  1. Extend this example to store and display a full name and address record.

Twelve

Implement a Menu

  1. 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

  1. 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

  1. Find other examples of recursive functions. Implement one of them.

Fifteen

Mini Project

  1. 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.