Echo vs Print

This is a discussion on "Echo vs Print" within the PHP Forum section. This forum, and the thread "Echo vs Print are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old May 30th, 2005, 17:01
Junior Member
Join Date: May 2005
Location: North Carolina
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Echo vs Print

Hello All -

I've been nosing around forums and looking at code posted - I keep seeing echo being used and it is not mentioned in the PHP5 book I am reading. I looked for echo in the back of the book and it is not mentioned at all.

Is there a preference or was echo replaced with print for PHP5 as I know nothing about PHP 3 or 4?

I was playing around with a very simple script that uses three lines of echo to print out strings where one line of print with the strings concantenated worked also.

Just curious as to why my book doesn't mention echo.

Thanks
Sqrlgrl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old May 30th, 2005, 18:56
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
There has been a lot of debate about print and echo in the PHP community over the years. There is actually almost no difference between them. In fact some people use echo just because it looks cooler.

Basic tests show that echo is faster, the reason being that echo returns nothing, print returns true, but these tests are not definitive.

The only actual difference between them in terms of use is that print can be used as a function:
Code: Select all
// Because echo is not a function, following code is invalid. 
($some_var) ? echo 'true' : echo 'false';

// However, the following examples will work:
($some_var) ? print('true'): print('false'); // print is a function
echo $some_var ? 'true': 'false'; // changing the statement around
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old May 30th, 2005, 19:07
Junior Member
Join Date: May 2005
Location: North Carolina
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks

For now I will stick with print since that is what the book is teaching.

I've been looking around the whole forum and reading some of the Flash Actionscript posts.

You're a very busy man Karl! Looks like everyone keeps you on your toes with their questions and your answers are always explaining why and not just an answer - very helpful.

Very glad I found this site!!

Sqrlgrl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old May 30th, 2005, 22:31
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
It certainly keeps me busy - and I enjoy it! I also learn a great deal this way - having to explain things keeps them fresh in my mind and I often have to learn new things to answer questions. Thanks for your kind comments!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
echo, print

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
echo proxy to csv stiassny JavaScript Forum 1 Apr 13th, 2008 16:51
How do I echo <?php ..... AdRock PHP Forum 12 Sep 14th, 2007 13:20
Echo and If simonb PHP Forum 2 Aug 27th, 2007 16:22
how to echo 2 classes geyids PHP Forum 3 Aug 9th, 2007 13:47
Echo and Sessions kool77 PHP Forum 6 Jun 1st, 2007 22:32


All times are GMT. The time now is 04:26.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42