Murdoch University Logo B211 Internet Computing

Laboratory Week 8 - Reading Files and String Manipulation in PHP


Learning Objectives:

Before doing the tutorial, please read:

Software required:

Exercises:

  1. Retrieve the HTML form and PHP script you created for exercise 4 from week 7. Add to your PHP script a function called NumberOfDays, that takes one parameter. The parameter should be a string corresponding to the name of a month, and the subroutine should return the number of days in that month as a return value. Change your script so that it calls this function.
  2. Write a PHP script which reads from a text file, and prints out all the lines in the file to the browser. Create your own text file to test your script with. You do not need to use an HTML form for this - just access the PHP script directly from your browser's URL box.
  3. Modify your PHP script in (2) so that instead of printing out every line, it only prints out the lines where the word "b211" appears. Create your own text file to test your script.
  4. Modify your PHP script in (3) so that instead of not printing out the lines with the word "b211", it prints out the lines with the word "b211" replaced with "[deleted]".
  5. Write a PHP script which reads from a text file, and prints out all the lines in the file but with all lower case characters turned into upper case. Create your own text file to test your script with.

Remember to read the week's development on the Internet by scanning through relevant articles in the IT section of Tuesday's the Australian newspaper - use the online version or the physical copy in the University library. Get into the habit of keeping up with current developments. Test your knowledge of major developments by going through the Good News Week self-tests.

H.L. Hiew
Unit Coordinator


Document author: H.L. Hiew, Unit Coordinator
Last Modified: Saturday, 14-Sep-2002 01:05:00 MST
Disclaimer & Copyright Notice © 2002 Murdoch University