Practice 2

Main | Static vs. Dynamic Websites | Using PHP | A Simple PHP Program | Variables and Operators | Practice 1 | Solution 1 | Loops | Practice 2 | Solution 2 | Functions | Practice 3 | Solution 3 | Conditionals | Practice 4 | Solution 4

This exercise will test your knowledge of PHP loops.

Some people often use a lot of repeated statements in their HTML, to space things out or make them line up. One way to implement this page, is the following:

<html>
I like 
<br><br><br><br><br>
to space 
<br><br><br><br><br><br><br> 
things 
<br><br><br><br><br><br> 
out
</html>

Note: There are a different amount of spaces on each line.

Use PHP's ability to loop to implement the above page using only one <br> tag per line. Use for loops for the first and last condition and use while loops for the middle condition.

To complete this exercise you must:

  1. Create a file in "public_html/php" called "space.php".
  2. Make "space.php" viewable from the web.
  3. Fill in "space.php" with this incomplete code.
  4. Complete the PHP section of the incomplete code and run your program.

HINT: When inserting loops into the above, you ought to vary the amount of times that the loop iterates by changing one condition in the loop statement.


jfulton [at] member.fsf.org
22 Aug 2013