Specifications

As you have probably guessed, using the echo construct has a very simple result; it prints (or
echoes) the string passed to it to the browser. In Figure 1.2, you can see the result is that the
text “Order processed.” appears in the browser window.
You will notice that a semicolon appears at the end of the echo statement. This is used to sepa-
rate statements in PHP much like a period is used to separate sentences in English. If you have
programmed in C or Java before, you will be familiar with using the semicolon in this way.
Leaving the semicolon off is a common syntax error that is easily made. However, its equally
easy to find and to correct.
Whitespace
Spacing characters such as new lines (carriage returns), spaces and tabs are known as white-
space. I would combine the paragraph above and the one below and form one cohesive para-
graph explaining how spacing characters (whitespace) is ignored in PHP and HTML.
As you probably already know, browsers ignore whitespace in HTML. So does the PHP
engine. Consider these two HTML fragments:
<h1>Welcome to Bob’s Auto Parts!</h1><p>What would you like to order today?
and
<h1>Welcome to Bob’s
Auto Parts!</h1>
<p>What would you like
to order today?
These two snippets of HTML code produce identical output because they appear the same to
the browser. However, you can and are encouraged to use whitespace in your HTML as an aid
to humansto enhance the readability of your HTML code. The same is true for PHP. There is
no need to have any whitespace between PHP statements, but it makes the code easier to read
if we put each statement on a separate line. For example,
echo “hello”;
echo “world”;
and
echo “hello”;echo “world”;
are equivalent, but the first version is easier to read.
Comments
Comments are exactly that: Comments in code act as notes to people reading the code.
Comments can be used to explain the purpose of the script, who wrote it, why they wrote it the
Using PHP
P
ART I
16
03 7842 CH01 3/6/01 3:39 PM Page 16