Assignment 2

Question 1

Part A

Start:
$names = "Harry Potter, ron Weasley, Hermione Granger, lavender brown, Pavarti patil, NEVILLE Longbottom, Seamus FiNNegan, Dean Thomas"
Split the string into an array called $arrayNames:
$arrayNames = array(8) {
  [0]=>
  string(12) "Harry Potter"
  [1]=>
  string(11) "ron Weasley"
  [2]=>
  string(16) "Hermione Granger"
  [3]=>
  string(14) "lavender brown"
  [4]=>
  string(13) "Pavarti patil"
  [5]=>
  string(18) "NEVILLE Longbottom"
  [6]=>
  string(15) "Seamus FiNNegan"
  [7]=>
  string(11) "Dean Thomas"
}
Add draco Malfoy to the end of the array (assume you don't know how long the array is):
$arrayNames = array(9) {
  [0]=>
  string(12) "Harry Potter"
  [1]=>
  string(11) "ron Weasley"
  [2]=>
  string(16) "Hermione Granger"
  [3]=>
  string(14) "lavender brown"
  [4]=>
  string(13) "Pavarti patil"
  [5]=>
  string(18) "NEVILLE Longbottom"
  [6]=>
  string(15) "Seamus FiNNegan"
  [7]=>
  string(11) "Dean Thomas"
  [8]=>
  string(12) "draco Malfoy"
}
Do a case-insensetive sort of the array:
$arrayNames = array(9) {
  [7]=>
  string(11) "Dean Thomas"
  [8]=>
  string(12) "draco Malfoy"
  [0]=>
  string(12) "Harry Potter"
  [2]=>
  string(16) "Hermione Granger"
  [3]=>
  string(14) "lavender brown"
  [5]=>
  string(18) "NEVILLE Longbottom"
  [4]=>
  string(13) "Pavarti patil"
  [1]=>
  string(11) "ron Weasley"
  [6]=>
  string(15) "Seamus FiNNegan"
}
Use a loop to capitalize just the first letters of each name:
$arrayNames = array(9) {
  [7]=>
  string(11) "Dean Thomas"
  [8]=>
  string(12) "Draco Malfoy"
  [0]=>
  string(12) "Harry Potter"
  [2]=>
  string(16) "Hermione Granger"
  [3]=>
  string(14) "Lavender Brown"
  [5]=>
  string(18) "Neville Longbottom"
  [4]=>
  string(13) "Pavarti Patil"
  [1]=>
  string(11) "Ron Weasley"
  [6]=>
  string(15) "Seamus Finnegan"
}
Output to an unordered list, styled with .griff if their name has an 'H' in it, and .rav otherwise.
  • Dean Thomas
  • Draco Malfoy
  • Harry Potter
  • Hermione Granger
  • Lavender Brown
  • Neville Longbottom
  • Pavarti Patil
  • Ron Weasley
  • Seamus Finnegan
  • Part B

    Start:
    I swear to tell the whole truth
    Insert "solemnly" before the word "swear" by counting from the beginning:
    I solemnly swear to tell the whole truth
    Replace everything starting at "whole" with "no good", counting from the end of the string:
    I solemnly swear to tell the no good
    Remove the words "tell the" using a php function to determine that starting position:
    I solemnly swear to no good
    Insert the words "I am up", before "to" using a PHP function to determine the starting position:
    I solemnly swear I am up to no good
    This would have been way easier if we'd used regular expressions instead of a substring-replace...

    Part C

    Enter the dimensions for which you'd like to generate a multiplication table (between 4 and 32):

    Question 2

    Question 2 is supposed to be a series of different pages. However, because I spent so long making the borders on the left side look so nice, I'm just going to embed those separate pages using an <iframe>. This will let me update it with PHP, but keep it looking like it's on this page.

    If you'd like to see it on a separate page, it can be found here.