Prev | Current Page 135 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

");
?>
$season = "summertime";
print "

I love the $season.

";
?>
62 CHAPTER 3 ?–  PHP B ASICS
print "

I love the
summertime.

";
?>
All these statements produce identical output:
I love the summertime.
?– Note Although the official syntax calls for the use of parentheses to enclose the argument, they??™re
not required. Many programmers tend to forgo them simply because the target argument is equally
apparent without them.
Alternatively, you could use the echo() statement for the same purposes as print().
While there are technical differences between echo() and print(), they??™ll be irrelevant
to most readers and therefore aren??™t discussed here. echo()??™s prototype looks like this:
void echo(string argument1 [, ...string argumentN])
As you can see from the prototype, echo() is capable of outputting multiple strings.
The utility of this particular trait is questionable; using it seems to be a matter of preference
more than anything else. Nonetheless, it??™s available should you feel the need.
Here??™s an example:
$heavyweight = "Lennox Lewis";
$lightweight = "Floyd Mayweather";
echo $heavyweight, " and ", $lightweight, " are great fighters.";
?>
This code produces the following:
Lennox Lewis and Floyd Mayweather are great fighters.
CHAPTER 3 ?–  PHP BASICS 63
If your intent is to output a blend of static text and dynamic information passed
through variables, consider using printf() instead, which is introduced next.


Pages:
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147