Otherwise,
if you??™d like to simply output static text, echo() or print() works great.
?– Tip Which is faster, echo() or print()? The fact that they are functionally interchangeable leaves
many pondering this question. The answer is that the echo() function is a tad faster because it returns
nothing, whereas print() will return 1 if the statement is successfully output. It??™s rather unlikely that you??™ll
notice any speed difference, however, so you can consider the usage decision to be one of stylistic concern.
The printf() Statement
The printf() statement is ideal when you want to output a blend of static text and
dynamic information stored within one or several variables. It??™s ideal for two reasons.
First, it neatly separates the static and dynamic data into two distinct sections, allowing
for easy maintenance. Second, printf() allows you to wield considerable control over
how the dynamic information is rendered to the screen in terms of its type, precision,
alignment, and position. Its prototype looks like this:
boolean printf(string format [, mixed args])
For example, suppose you wanted to insert a single dynamic integer value into an
otherwise static string:
printf("Bar inventory: %d bottles of tonic water.", 100);
Executing this command produces the following:
Bar inventory: 100 bottles of tonic water.
In this example, %d is a placeholder known as a type specifier, and the d indicates an
integer value will be placed in that position.
Pages:
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148