PHP
September 28th, 2009
PHP is a powerful scripting language used all over the Internet. In addition to driving this web page and almost all other blogs. It is also a key element of many other web pages both large and small.
PHP is a bit different from other programming languages in a few ways. The biggest difference is that PHP is accessed through a web browser and is executed on a web server (not a local computer or through a compiler). This concept can be difficult to understand when you are first learning php. On a traditional programming language (c/c++/java) you typically code the program in either a text editor or authoring environment, convert it into binary or an assembly language that your Operating System or processor can understand using a compiler, then run it on your local machine.
When you are creating a php program you typically code the program in a text editor, upload it to a server (real or virtual), and access it through a web address (local or through the internet). When you go to access the php program through your browser the program is then executed on the web-server. The results from the program are then displayed on the screen.
There are many benefits to using php in this way. For large online applications users don’t have to download the whole program they just use it on the online server and it only sends them the answers. This also reduces the amount of bandwidth required for a program to run. When coding in PHP it also means that you don’t have to worry about what computer it is being executed on and what system configuration the user is on as all they need is a web browser.
There are many online resources to use in learning php. The www.w3schools.com website is still a good resource for learning php. I would consider their resources very informative and thorough. Previously however I’ve used http://devzone.zend.com/tag/PHP101 for php. I find their tutorials a lot more fun and practical from a students perspective. When you get to the site find tutorial 1.
Before you can begin with php, you need to be able to test your files on a server. For this I have set up a web server for us to test our programs on. Instructions will be given in class on how to set this up.
Assignment 1
This will include some small program tasks that you should be able to complete with little effort.
Task 1 – Make your name print on screen 30 times
Task 2 – Make your name print on screen a specific number of times as specified by user input
Task 3 – Take 2 numeric user inputs and have the program subtract the larger of the two inputs from the other. The order in which they are entered shouldn’t matter.
Task 4 – Have the user guess a number between 0-9. Ensure that they entered a valid input and output a different message for each possible user input.
All of these asks should be easy to complete provided you have gone through the first 3 tutorials in class.
Assignment 2
Task 1 – Create a program that will take the user input of an email address and add it to a text file. Have the program output the file and give the user an opportunity to input more addresses.
Task 2 – Have a program (or build it into task 1) to sort the list alphabetically and return it to the text file.
Note you may need some way of triggering an end of a email address (a specific character or indicator).
Assignment 3
For this assignment you are given the following lines of code. I want you to determine the output without coding the program. See the attached file here.
KPRDSB