Echo ""; Or Print"";

Started on the old forum in June 2006 · view the original in the archive · old links redirect here

38 replies · 2,976 views · started 20 years ago · 1 min read

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.

11 participants
abhisar #21

echo ''; works really great.I will soon be replacing print with echo.

lamar-wap #22

i love it echo "Lamar Rulez Ok";

abhisar #23

echo 'Me too.lol ';

abhisar #24

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.

hardstyle Developer · 154 posts #25

from where did you get that text above?

8th wonder of the world

blackhowk Senior · 411 posts #30

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

blackhowk Senior · 411 posts #31

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

Guest #33

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)

djdevil89 Senior · 287 posts #34

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 />";
}
ori Lead · 512 posts #35

thats not true echo "$stuff"; works just not practical lol als o u can do this in links href="index.php?act=".$act['post']." can be href="index.php?act=$act" its lot neater theres no reason to wrap it in "

djdevil89 Senior · 287 posts #37

ori "$stuff" works lol but not '$stuff' and i somehow saw the board converted my code somehow

foreach ($_SERVER as $server => $value)
{
echo "$server is $value<br />";
}
djlee Developer · 224 posts #39

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

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close