Page 1 of 1

Difference in print and echo?

Posted: Wed Apr 02, 2003 2:44 pm
by penguinboy
I've noticed in a lot of code people tend to use "print" for html, and "echo" for php.

so... in like....

index.php
<?
$hello = "Hello world";
print ("<table><tr><td>");
echo $hello;
print ("</td></td></table>");
?>

I was wondering if there was any logical reason for this.

A friend gave his opinon:
Print just prints, bypasses memory.
Echo goes through memory before it prints to the screen.

So according to him, echoing a var would be faster(slightly) than printing the var.
And printing html would be faster(slightly) than echoing html.

I don't know if hes right or not, so I thought I'd post the question here.


--pb

Print and Echo

Posted: Wed Apr 02, 2003 2:50 pm
by oQEDo
You can use print to set a return value, ie:

$myVal = print "Hello";
Therefore $myVal will be 1

echo is slightly faster as it does not do this.

Posted: Wed Apr 02, 2003 3:23 pm
by volka
and echo 'can', $take, 'multiple arguments'; ;)

Posted: Wed Apr 02, 2003 7:29 pm
by phice
echo is my friend. :)

Posted: Thu Apr 03, 2003 1:22 am
by twigletmac
echo is also one character less to type than print...

Mixing echo's and print's is a bit strange, most people tend to pick one and stick with it.

For the official word on the differences (which as people have already stated are not exactly huge):
http://www.php.net/manual/en/function.echo.php
http://www.php.net/manual/en/function.print.php

Mac