Laboratory Week 8 - Reading Files and String Manipulation in PHP
Learning Objectives:
- Learn to write functions, read files, and do basic string manipulation in PHP.
Before doing the tutorial, please read:
- Week 5 lectures on PHP programming.
- Textbook Web Programming chapter 12.
- Review what you learnt in the week 7 exercises.
Software required:
- This lab requires connection to the server phoenix.murdoch.edu.au via a SSH and an FTP program. Instructions on how to do so is given in lab week 3.
- This lab also requires a graphical web browser (like Netscape Navigator or Microsoft Internet Explorer), and a text editor (like Notepad).
Exercises:
- 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.
- 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.
- 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.
- 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]".
- 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