This is the P2PU Archive. If you want the current site, go to www.p2pu.org!
Introduction to PHP
Assignments for Week #2 - Letters and Numbers
1) http://codepad.org/gIE1cMCv - Modify this webpage code chunk according to the following parameters:
-
Change the title of the page to “My Haiku”, where you use your own given name instead of “my”.
-
Output the three lines of the haiku in the body without including your <br /> tags inside <?php ?> tags.
2) http://codepad.org/uGjjc0nK - Modify this webpage code chunk according to the following parameters:
-
Remove the line break tab from the string and put it in the HTML elements. In general, it’s best to leave HTML elements in HTML output, unless you have a really good reason for outputting them with PHP.
-
Currently, the variables $line2 and $line3 don’t output anything because they were never assigned. Assign a string value to them. Also, it’d be nice if you made a new structurally valid haiku.
-
Let’s make the title generated dynamically from a variable. Create a variable named $title after $line3. Assign a string of your choosing to $title. Output $title inside the <title> tag.
3) http://codepad.org/21YrQa0T - Modify this code chunk according to the following parameters:
-
Generate an output of “10” instead of “8” without modifying the values of $a, $b or $c, without creating new variables, and without using string variables or direct HTML output.
-
Generate an output of “21” instead of “8” using similar restrictions to those in step 1.
4) http://codepad.org/0EZRdY1t - Using this webpage code chunk as an example, discover the answers to the following questions:
-
What is the result type when you add two integers?
-
What is the result type when you subtract two integers?
-
What is the result type when you subtract a float from an integer?
-
What is the result type when you subtract an integer from a float?
-
What is the result type when you divide two integers that produce a zero remainder?
-
What happens when you try to add an integer or float to a string? What is the rule for how PHP handles strings in mathematical expressions?
5) http://codepad.org/RUOhOK2x - Modify this code chunk according to the following parameters:
-
Rewrite the first echo statement to produce the following string: “pqrstklmnoabcdezfghij”. Do not change the preceding variables’ names or values!
-
Rewrite the third echo statement to produce the URL for the School of Webcraft main page.
6) Create your own code chunk on Codepad. Create at least two questions and their corresponding answers related to the code you wrote. The questions should relate to material in the readings for today. Come to the next meeting prepared to share your code and questions with the class.