The simple case of the command is to display a variable. For example,
the following would display your browser's identification string:
<?echo $HTTP_USER_AGENT>
This looks like this:
We can also display multiple variables with one echo statement.
For example, <? echo $HTTP_USER_AGENT, "Yet another variable"
>
This looks like this:
The optional formatting string is especially handy for numerical display. Assume for some reason we wanted to display floating point numbers to different levels of precision. Note that 10.0 and 3.0 we'll use instead of 10 and 3. Without the .0's the result will be treated as an integer and not a floating point value.
<?echo "%7.2f" 10.0 / 3.0>
This looks like this:
The "%.2f" instructs echo to display 3.3333 as floating point number with 2 significant digits after the decimal place.
The "%7f" instructs echo to display 3.3333 in a field that is at least 7 characters wide.
Now we will display 10.0 / 3.0 with:
<?echo "%.9f" 10.0 / 3.0>
This looks like this:
See your Unix man pages, or any C language manual for the formatting arguments for the printf function for a complete list of all the formatting parameters available. The echo command supports most of the same features and they are too exhaustive to cover completely here.
Also, read the php/doc/doc.html file for more information on the echo command.