PHP Basics Assignment

The purpose of this assignment is to give you some hands-on experience with basic PHP syntax. It is broken up into two segments.

 

Section 1 - Print the following poem exactly as displayed:

'Twas brillig and the slithy toves 
	Did gyre and gimble in the wabe: 
All mimsy were the borogoves, 
	And the mome raths outgrabe.


"Beware the Jabberwock, my son! 
	The jaws that bite, the claws that catch! 
Beware the Jubjub bird, and shun 
	The frumious Bander$natch!" 

The poem is a segment from Lewis Carol's Jabberwock. Both stanzas (paragraphs) are to be printed entirely within PHP print statements. The first stanza requires one print(''); and the second, one print(""); notice the distinction between the types of quotes required for both print statements. Be sure to use one print statement per stanza. No mixing of quotes; the print('') can not contain a double quote "; print("") can not contain a single quote '.

The first stanza requires a variable substitution for the word brillig. Assign a variable this string value and substitute it into its appropriate location within the corresponding print statement.

You're looking at the printed lines from the PHP program, more specifically unrendered HTML. It's important to make this distinction as you format the output using special types of characters.


Section 2 - Distance is equal to velocity multiplied by time. (We'll assume that velocity is scalar - instead of velocity, we'll just call it speed) In other words, how far one travels is determined by the speed times time. The basic unit for speed is miles per hour (mi/h), time hours (h), and distance miles (mi); store these unit values as variables. Determine what distance 'John' has traveled going 50 mi/h over a span of 2 hours. Second, determine how much time has transpired when 'John' has traveled a distance of 70 mi at a rate of 55 mi/h. Print out the results along with their appropriate units (i.e. Speed = 33 mi/h). The output for the calculations should look exactly like:

John traveled _mi when traveling at a rate of _mi/h over a period of _h.
John traveled _mi when traveling at a rate of _mi/h over a period of _h.

The units should be italicized and the blanks should be filled in with their corresponding values. Use double quotes " for the print statement(s) for this section.

You don't see HTML tags here because you're replicating the result of rendered HTML. Don't duplicate the source code on this page for the above passage; you'll notice that it doesn't quite satisfy the specifications.

 

Specs

  • Use one PHP script.
  • All numeric data should be stored as variables. I shouldn't see $distance = 34 * 2. Certain literal values require variables as declared in the section descriptions (i.e. 'units'). Don't worry about storing other literal data as variables (i.e. you don't need $message = "John traveled _ ...");
  • Calculations must be done in PHP. Don't use a calculator to get any of the results.
  • Use <?php ?> tags and the .php extension.
  • Print out opening and closing HTML tags outside PHP tags.
  • Resulting document should be well-formed and strictly HTML compliant.
  • Add a header comment /**/ to the top of your script. It should contain your name, email address, and date of creation.
  • Add comments /**/ to the beginning of each section and include a brief description and your algorithm for that section.
  • Add comments // to each variable they should give a very brief explanation of what the variable is for. These comments should be posted on the same line as the variable declaration.
  • All HTML tags must be printed out on separate lines; separate from other tags and text ('<html><head>' or '<p>Here we go' won't work)
  • The only function call you are allowed to use is print ();
  • Do not print extra information out, especially a header for the page.

Notes

  • Refer to on-line tutorials and zipped class programs for help.
  • As always, email me questions or set up an appointment for further assistance.
  • If you're having problems getting your document to validate, check the errors for the presence of stylistic/presentation-like tags or attributes. Table tags might be the source of your problems. Use basic minimalistic HTML...nothing fancy.
  • Validate your results; be sure the arithmetic is plausible by assessing whether the results make sense.
  • Don't forget about escape characters.
  • If you get parser errors, be sure you have matching opening and closing quotes and semi-colons at the end of each statement.

Turning it in
You are to post your script in your Ruby assignments folder. You should also email me the script. Not emailing the script as an attachment will result in zero points earned.