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
Difference in print and echo?
Moderator: General Moderators
-
penguinboy
- Forum Contributor
- Posts: 171
- Joined: Thu Nov 07, 2002 11:25 am
Print and Echo
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.
$myVal = print "Hello";
Therefore $myVal will be 1
echo is slightly faster as it does not do this.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
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
