PHP-EXERCISES

Exercise 1. Simple currency calculator utility

Implement simple currency calculator utility-program, which can be used to calculate currency conversions from dollars to euros. Exchange rates can be found for example on http://www.x-rates.com/d/EUR/table.html. Implement simple HTML-form where user user can input amount of dollars (currency.html) and PHP-script (calculate.php) to calculate currency conversion. PHP-script will read the input values from HTML-form and perform conversion by multiplying dollars with current exchange rate.

Exercise 2. Simple body mass index calculator utility

Implement simple calculator utility-program, which can be used to calculate person's Body Mass Index (BMI). The formula for calculating BMI is weight / (height * height). Implement simple HTML-form (bmi.html) where user can input weight (in kilogramms) and height (in meters, floating point is punctuation mark). PHP-script (bmi.php) called from form's action-method will execute the calculation in print out the result.

Exercise 3. Simple heart rate limits calculator utility

Implement simple calculator utility-program, which can be used to calculate person's heart rate limits when doing aerobic ecercise. The formula for calculating hear rate limits is (220-age) * 0.85 for upper limit and (220-age) * 0.65 for lower limit. For example heart rate limits for person aged 30 are (220-30) * 0.85 = 161.5 and (220-30) * 0.65 = 123. Implement user interface and php-script to execute calculation.

Exercise 4. Salary calculator

Implement web-application, which can be used to calculate salaries. Total salary (net income) paid is gross income (asked from user) diminshed by tax percentage (asked from user) and pension insurance payment (fixex percentage 4.30%). Desing user interface for asking necessary input (HTML-form) and PHP-script to execute calculation and printing out the result.

Exercise 5. Annuity calculator

Implement annuity calculator for web. Formula to calculate annuity for monthly payment is as follows:

You can also check out example from SAMPO-pankki. Use pow function of PHP to perfom powerage calculation.

Exercise 6. Correct answer

Implement simple web-application (see picture below) that asks question from user and evaluates if the answer is correct. Pictures can be found from school's Y-networkdrive. Use conditional statement to determine, if answer is correct or not.

Exercise 7. Distance converter

Implement calculator to convert distances between (both ways) miles and kilometres. One mile is about 1.609 kilometres. User inteface (distance.html) has one text-input, two radio-buttons, submit and reset -buttons. Values are posted to PHP-script (distance.php) which calculates the conversions according the user input.

Exercise 8. Thermometer converter

Implement calculator to convert temperatures between Fahrenheit and Celcius. Formulas for calculation can be found for example from here.

Exercise 9. (Ski-)Stick height calculation

Implement calculator that can be used to calculate stick height for cross-country skiing or nordic walk. Formula:

Implement user interface and script to calculate result (see pictures below).

Exercise 10. Housing allowance

Implement application, which can be used to calculate housing allowance for student. Housing allowance is 80% of reasonable housing cost. Reasonable housing cost is between 33.64252 . if cost is under 33.64 no allowance is paid. If cost is over 252 , maximun allowance 201.60 is paid. If cost is between 33.64 and 252, allowance is 80%.

Exercise 11. Print multiplication table

Implement PHP-script (no html is needed) to print out multiplication table of number 10 (see picture below). User for-structure and table html-element.

Exercise 12. Print timetable

Implement PHP-script to print out times from 8 to 16 to HTML-table.

Exercise 13. Print timetable with day of week

Modify previous exercise so that also day of weeks are printed to page necessary amounts of columns are printed out to each row. Use conditional and loop -structures to implement exercise.

Exercise 14. Fixed amortization schedule

Implement application to calculate amortization mortage table.
Example calculation:
Capital: 100 000
Interest: 5 % / 12 = 0.416
Time: 10 years (10 * 12) = 120 months

Fixed payment for every month is 100 000/120 = 833.33 (capital / time in months).
Interest payment is diminished every month:
1st interest: 100 000 / 100 * 0.416 = 416 , total payment for the month is 833.33 + 416 = 1250
2nd interest: (100 000-833.33) / 100 * 0.416 = 412.5 , total payment for the month 833.33 + 412.5 = 1246
3rd interest: (99166.67 - 833.33) / 100 * 0.416 = 409 , total payment for the month 833.33 + 409 = 1243
...
...
...
Design and implement user interface to ask capital, interest (percentage) and time (in years) from user (examples mentioned below may have more fields). Implement also PHP-script that reads input values, calculates amortization table and prints it out. You can also check out examples on SAMPO-pankki. and http://www.oamk.fi/~jjuntune/php/examples/loan.htm.

Exercise 15. Print ASCII-table

Implement PHP-script that prints out ASCII-table (codes from 1 to 255) to browser as HTML-table. Use for-statment and chr-function.

Exercise 16. User input validation

Modify BMI-application (exercise 2) so that user input is validated. Maximum length for height is 4 characters and value must be float value. Maximum length for weight is 3 characters and value must be an integer. If user gives incorrect input, notification is displayed.

Exercise 17. Refresh page automatically

Implement PHP-page (with some content) which will be refreshed after every 5 seconds. You can confirm that page is refreshed by looking the (green) status bar of your browser. Check example how to use header for refreshing.

Exercise 18. Simple emailing application

Implement simple application that can be used to sent emails. Use email-function and check out the example from course slides.

Exersice 19. Validate SIM(Subscriber Indentity Number)-card number

Implement application that validates SIM-card number using Luhn's-formula Example of correct SIM-card number is. 0105 1231 4161
Validation goes:
0 1 0 5 1 2 3 1 4 1 6 1
2 1 2 1 2 1 2 1 2 1 2
0 1 0 5 2 2 6 1 8 1 3 = (29 + 1) mod 10 ==0
Check out the example from slides