Page 108 - Beginning PHP 5.3
P. 108
Part II: Learning the Language
Finally, you reach the end of the main do...while loop. As you’d expect, the loop ends once the
pigeon coordinates match the home coordinates:
} while ( $pigeonX != $homeX || $pigeonY != $homeY );
In addition, the script used various CSS styles (embedded within the head element of the page) to
improve the appearance of the maps.
Mixing Decisions and Looping with HTML
In Chapter 2 , you learned that you can embed PHP within HTML Web pages and, indeed, most of the
examples in this book use this technique to wrap an XHTML page header and footer around the PHP code.
You also learned that you can switch between displaying HTML markup and executing PHP code by
using the < ?php ... ? > tags. This feature really comes into its own with decisions and looping,
because you can use PHP to control which sections of a Web page are displayed (and how they ’ re
displayed).
Here ’ s a simple example:
< !DOCTYPE html PUBLIC “ - //W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1 - strict.dtd” >
< html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en” >
< head >
< title > Fibonacci sequence < /title >
< link rel=”stylesheet” type=”text/css” href=”common.css” / >
< style type=”text/css” >
th { text - align: left; background - color: #999; }
th, td { padding: 0.4em; }
tr.alt td { background: #ddd; }
< /style >
< /head >
< body >
< h2 > Fibonacci sequence < /h2 >
< table cellspacing=”0” border=”0” style=”width: 20em; border: 1px solid
#666;” >
< tr >
< th > Sequence # < /th >
< th > Value < /th >
< /tr >
< tr >
< td > F < sub > 0 < /sub > < /td >
< td > 0 < /td >
< /tr >
< tr class=”alt” >
< td > F < sub > 1 < /sub > < /td >
< td > 1 < /td >
< /tr >
70
9/21/09 8:52:13 AM
c04.indd 70
c04.indd 70 9/21/09 8:52:13 AM