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 ("
This will be displayed across
two lines
");
$me="Fred";
print "I am $me";
echo "I am $me
";
echo '$me='.$me."
";
?>
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 <<
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 =[data here]?> can be quite useful
for outputting short data:
Player of the month is ="$strPlayer"?>
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().