Echo ""; Or Print"";
Started on the old forum in June 2006 · view the original in the archive · old links redirect here
TL;DR · summary of 38 replies
- - Echo ''; is marginally faster than print "", but the difference is negligible.
- - The choice between echo "" or print "" does not affect WAP users or browsers, and it doesn't matter which one to use for most cases.
- - Some developers prefer using echo because it's shorter and can be used in more complex expressions.
Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.
There is a difference between the two, but speed-wise it should be irrelevant which one you use. print() behaves like a function in that you can do: $ret = print "Hello World";And $ret will be 1That means that print can be used as part of a more complex expression where echo cannot. print is also part of the precedence table which it needs to be if it is to be used within a complex expression. It is just about at the bottom of the precendence list though. Only "," AND, OR and XOR are lower.echo is marginally faster since it doesn't set a return value if you really want to get down to the nitty gritty.If the grammar is: echo expression [, expression[, expression] ... ]Then echo ( expression, expression ) is not valid. ( expression ) reduces to just an expression so this would be valid: echo ("howdy"),("partner");but you would simply write this as: echo "howdy","partner"; if you wanted to use two expression. Putting the brackets in there serves no purpose since there is no operator precendence issue with a single expression like that.
ya all are discussing about one simple command which are both used just for commenting and both works well and good whether on wap or web External image (may be gone)
Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!
One difference is that echo() can take multiple expressions:
<?php echo "The first", "the second"; ?>Print cannot take multiple expressions. Echo has the slight performance advantage because it doesn't have a return value. True, echo is a little bit faster, but nothing you'll notice. I tried outputting around 10000 strings, there was a difference of around .02 seconds
There is a difference between the two, but speed-wise it should be irrelevant which one you use. print() behaves like a function in that you can do: $ret = print "Hello World";And $ret will be 1That means that print can be used as part of a more complex expression where echo cannot. print is also part of the precedence table which it needs to be if it is to be used within a complex expression. It is just about at the bottom of the precendence list though. Only "," AND, OR and XOR are lower.echo is marginally faster since it doesn't set a return value if you really want to get down to the nitty gritty.If the grammar is: echo expression [, expression[, expression] ... ]Then echo ( expression, expression ) is not valid. ( expression ) reduces to just an expression so this would be valid: echo ("howdy"),("partner");but you would simply write this as: echo "howdy","partner"; if you wanted to use two expression. Putting the brackets in there serves no purpose since there is no operator precendence issue with a single expression like that.
copy paste from http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40
pmpl blackhowk bro that was a cool one External image (may be gone)k:
Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!
lol use print ""; if u want to print text on some page, use echo ""; if u want to execute some code with text, use ''; tags if u want only one print/echo in page, i use it like that External image (may be gone)
Also note
$string = 'hello world';
echo '$string';
will not work instead better use
$string = 'hello world';
echo ' '.$string.' ';
if you use echo or print is your own decision i personally like print 😊 most scripts use echo so i want to be different
foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}
Its gud coding practise. This: echo 'helo'; is alot neater. And so is this: echo "I am a {$foo} and you are a {$bar}.";
echo is slightly faster..print only takes one parameter, while echo can have multiple parameters..print returns a value 1, so it can be used as a function..
My Blog: http://jhommark.blogspot.com My Facebook: http://www.facebook.com/jhommark My Official Site: http://www.undergroundweb.tk My Community Site: http://undergroundwap.xtreemhost.com
the speed of the two is negligable, you will NEVER use enough echo or prints to make the use of either noticeable. There is one main reason for the two, echo is not a function, this means it cannot be used inside another function as the callback whereas print can. I do say use echo as my own opinion as i prefer it but i wouldnt go spending hours changing it on your site, by the look of the code ive seen on this forum theres a hell of a lot more badly optimised code that would produce much better results if you fixed them.
but a few facts for you to chew on
echo is faster than print, its negligable but its there if you want to be perdantic. this is because print is a function/wrapper of echo
single quotes ' are faster than double quotes ", this is because when the interpreter sees a single code it will parse everything inside of those quotes as plaintext, double quotes allow variables to be used without the need to break out of the string delimiters therefore strings inside double quotes are scanned for variables to be exchanged.
$user = "djlee";
echo 'welcome $user'; //prints welcome $user
echo 'welcome'.$user; //prints welcome djlee
echo "welcome $user"; //prints welcome djlee