RU beehive logo ITEC dept promo banner
ITEC 325
2014spring
ibarland

homelectshws
D2Lbreeze (snow day)

hw02
hw02: Functions that return (html) text

Due 2014.Feb.05 (Wed) 14:00. Submit on D2L, and a hardcopy of all three files utils.php, utils-test.php, silly-page.php. Finally, make sure I can view the last file's output via the web at https://php.radford.edu/~yourUserName/itec325/hw02/silly-page.php.

As in hw01, you'll have three files:

Notes:

  1. (10pts) Write a function string hyperlink( string $url, string-or-boolean $linkTxt ) which returns a string of html. If the provided $linkTxt is false (instead of a string), then use the $url as the link text.
    hyperlink( "http://www.gutenberg.org", "free books!" ) === "<a href='http://www.gutenberg.org'>free books!</a>"
    hyperlink( "myLocalFile.html", false ) === "<a href='myLocalFile.html'>myLocalFile.html</a>"

    Note that this is just a regular ol' function that takes in strings and returns strings!
    The fact that the strings happen to have angle-brackets in them means that the result might be useful to people generating html, but the function itself does't really care.

    (You don't need to come up with additional test cases, but you do need to actually include these tests or their equivalent. You can assume that neither string is ever empty.)

    Note how the input strings don't contain any quote-characters, but the returned result does (since HTML attributes must be quoted). I recommend that your generated html uses single quote marks around attributes, but you'll get full credit for either single- or double-quote marks, as long as it is valid HTML. Make sure your test case(s) express exactly what you want the desired output should be!

  2. (10pts) Thumbnails:
    1. What is the html element for an image with source pony.jpg (in the same directory), that is rendered 300px wide?
      Include your answer in a comment, in your test-file.
    2. What is the html for such an image which is also a link — where the link would take you to that file (not a html page — just that file).
      Include your answer in a comment, in your test-file.
    3. Make a test-case for thumbnail("pony.jpg",300); the expected-output should be a string that happened to be your answer.
      You don't need further test-cases for this problem.

      Pay close attention to the exact spacing you want to have. I recommend using single-quotes (') around the attribute-values. (We'll discuss this more on Monday.)

    4. Finally, implement the function thumbnail that takes in a string (a URL) and a number (the width in pixels), and returns a string that is an html link containing an image.

      For full credit, your function should call hyperlink as already written!

homelectshws
D2Lbreeze (snow day)


©2014, Ian Barland, Radford University
Last modified 2014.Feb.01 (Sat)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme