PHPWomen Site Home » PHPW Community » ZCE Study Group » echo vs print
echo vs print [message #2581] Thu, 26 February 2009 10:23 Go to next message
vicky7883  is currently offline vicky7883
Messages: 2
Registered: February 2009
Location: The Netherlands
Shiny and New
Hi,

I am learning PHP5 now, and wondering what is the different between echo and print in PHP5. Could anyone help? Thanks.

Vicky
Re: echo vs print [message #2583 is a reply to message #2581 ] Sat, 28 February 2009 16:08 Go to previous messageGo to next message
Anonymous Coward
Hiya!

Well, the difference are:

'Print' is a function. 'Echo' is not. For that reason Print receive just one parameter, which means it prints one thing. Echo can print a list of things separates by commas.

print ('something to print here');

echo 'something to print here', 'also another thing', 1;

I think also echo is more faster.

I hope it helps Smile
Re: echo vs print [message #2584 is a reply to message #2581 ] Sun, 01 March 2009 10:32 Go to previous messageGo to next message
lorna  is currently offline lorna
Messages: 414
Registered: October 2006
Location: Leeds, UK
Feeling Comfortable

Teknotica is right, confusingly though you can use echo with brackets just like a function! Personally I always use echo, sometimes with brackets

<?php
echo("hello world");
?>


and sometimes without

<?php
echo "hello world";
?>


I really think the two are interchangeable. Sometimes there are long mailing list arguments in differet places about one being faster than the other but realistically there aren't many applications where the speed of one over another will be the bottleneck!

Hope that helps,

Lorna


Lorna Mitchell (online at http://www.lornajane.net)
Re: echo vs print [message #2588 is a reply to message #2581 ] Sun, 01 March 2009 16:29 Go to previous messageGo to next message
vicky7883  is currently offline vicky7883
Messages: 2
Registered: February 2009
Location: The Netherlands
Shiny and New
Thanks. Now it's clear to me.

Vicky
Re: echo vs print [message #2616 is a reply to message #2583 ] Mon, 16 March 2009 07:21 Go to previous message
Marion  is currently offline Marion
Messages: 114
Registered: October 2006
Location: Amsterdam, The Netherland...
Member

Quote:

'Print' is a function. 'Echo' is not. For that reason Print receive just one parameter, which means it prints one thing. Echo can print a list of things separates by commas.


Reading code a collegue of mine had written, I found 'print' expressions without parentheses, and they worked fine. That made me think and check the PHP manual.

It seems that 'print' is not a function after all, it's a language construct like 'echo'. Both 'print' and 'echo' work with and without parentheses, but if you want to 'echo' a list of things, you should not use parentheses.
Another difference that has not been mentioned yet: 'print' has a return value (always 1), 'echo' has not.

regards,
Marion
Previous Topic:nooblet here
Next Topic:I did it!
Goto Forum:
  


Current Time: Tue Sep 7 10:35:41 EDT 2010

Total time taken to generate the page: 0.00983 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.0.
Copyright ©2001-2006 FUD Forum Bulletin Board Software