print echo

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

print echo

Post by shiznatix »

what is the difference between print and echo
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Straight from the manual
echo

(PHP 3, PHP 4, PHP 5 )
echo -- Output one or more strings
Description
void echo ( string arg1 [, string ...] )

Outputs all parameters.

echo() is not actually a function (it is a language construct) so you are not required to use parentheses with it. In fact, if you want to pass more than one parameter to echo, you must not enclose the parameters within parentheses.
print

(PHP 3, PHP 4, PHP 5 )
print -- Output a string
Description
int print ( string arg )

Outputs arg. Returns 1, always.

print() is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

In real life there is not much difference, which one you use but check this out:

Code: Select all

<?php
$string1="Hello ";
$string2="world";
echo $string1,$string2;
print $string1 . $string2;
?>
See the difference?
Post Reply