Contents / Previous / Next


print and echo

Both print() and echo() can be used for output. Both can span several lines, although they will be collapsed in HTML, try: <? print ("<PRE> This will be displayed across two lines </PRE>"); $me="Fred"; print "I am $me<p>"; echo "I am $me<p>"; echo '$me='.$me."<p>"; ?> The difference between print() and echo(): print() is a function, while echo() is a construct. Thus print() can return a boolean value.

The point "." concatenates strings.

In single quotes a variable is displayed as a string (you may also escape the dollar sign with a backslash).


Long Text

For long text you can use the "here-doc syntax" to define an "echo region": <? echo <<<my_text_region .... HTML text ... my_text_region; ?> The enclosing echo and end-marker must appear at the beginng of a line (PHP 4.2).


Shorthand output

There is also a The construct can be quite useful for outputting short data: <p>Player of the month is <?="$strPlayer"?></p>


printf -- Output a formatted string

printf() is a C-like function, it produces output according to format: int printf (string format [, mixed args...]) Where is also: print(), sprintf(), sscanf(), fscanf(), and flush().