PHP Exercises

As mentioned at the lecture, one cannot learn a programming language just by attending a lecture; it is important to get experienced by actually working with the language. Some of these exercises require material that was not covered at the lecture. As mentioned, there is a manual for the language at www.php.net
  1. Parameters: Expand the Weekplan example on the Arrays slide, such that for each lecture there is a link to a page called week.php sending the correct week number as a parameter to this page in the URL.
  2. File Manipulation: Make a script that takes a number N as argument and prints out the N'th line of the file brixtofte.txt. If N is negative or larger than the number of lines in the file, an error message should be printed. Do not forget the rules about manipulating with files! (close files after you, etc)

  3. String Processing: Make a PHP script where a user enters a text in a form and clicks a 'submit' button. The script should then show a page, where the number of occurences of the letter 'e' in the input string is shown.
  4. Arrays: Make a function PrintArray(Array,width,height) that takes a double indexed array and the height and width of this array and arranges it in a table. For instance the result of the call:

    PrintArray(array(array("Father","Mother","Son"),array("Homer","Marge","Bart")),3,2)

    should be:

    FatherMotherSon
    HomerMargeBart



Optional Hand-In

Citations: Make a citation index using PHP, both for getting a quote and for sharing a cool quote with others. The script should start with a page where the user can choose to get or enter a quote. Accordingly, the script should either The index could be a file where the different quotes are separated by lines that only contains a '%'. There is an example here.