Part 1: Numbers and Strings
1. Create a file called chapter1.php and create a basic blank webpage with an empty php script.
2. Create two variables named base and height and assign a different number value to each one. .5
marks
3. Create a variable called area and set it equal to ½(base * height). .5 marks
4. Round area to two decimal places. 1 mark
5. Display the following text: "The area of the triangle is" and include the value of the rounded
area variable. Use the string concatenation operator. .5 marks
6. Create a constant called MY_NAME and set it to your first name and your last name with a space
in between e.g. Bill Gates. .5 marks
7. Convert the MY_NAME constant to all uppercase using a string function. 1 mark
8. Display the following text using your name: "My first name is BILL GATES", use the tag
to make the name bolded. 1 mark
Part 1 Total: 5 marks
Part 2: Form Validation
1. Open up the a1p2.php file.
2. Make the form in a1p2.php send the form data to the same file. 1 mark
3. Add "Sticky Forms" to the form in a1p2.php 1 mark
4. Inside the a1p2.php file, validate the sent data for each input using the best practices from
chapter 2. 6 marks
5. Display the data for each input that passes the validation. 1 mark
6. Display an error message for each input that fails the validation. 1 mark
Part 2 Total: 10 marks
Part 3: Arrays and Strings
A) Write a PHP script that sorts all the words in this text by alphabetical order and then prints
them:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 2.5 marks
B) Open the a1p3.php file. Add a function that takes the inputted text as a parameter. The
function should check if there are any duplicate characters in the string. For example, the string
"cat", would return false. The string "kitten" (the letter t is duplicated), would return true. The
script should print whether the string has duplicates or not. 2.5 marks