[PHP] echo VS print : that's a cool behavior !
Hello everyone. We all know the difference between print and echo, but has someone ever tried to combine them together ?? Right, try this : ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); And guess the result ... Can someone explain it ? ( the result is : toctoc hihi u 1pupu zozo 1v 1tata 1coucou 1 )
Re: [PHP] echo VS print : that's a cool behavior !
On Tue, 2007-10-23 at 17:34 +0200, Julien Pauli wrote: ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); That's not cool, that's a mess. Why doe sit happen the way it does? First off, print() is a function so nesting functions means the innermost functions get processed first, this is why the output has mangled order. The 1's show up in the output because you're concatenating the return value of the print() function which is true for success. Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo VS print : that's a cool behavior !
On 10/23/07, Robert Cummings [EMAIL PROTECTED] wrote: On Tue, 2007-10-23 at 17:34 +0200, Julien Pauli wrote: ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); That's not cool, that's a mess. Why doe sit happen the way it does? First off, print() is a function so nesting functions means the innermost functions get processed first, this is why the output has mangled order. The 1's show up in the output because you're concatenating the return value of the print() function which is true for success. Agreed it's a mess, and I don't know why anyone would do it, but that's only part of the story. I don't think the OP was wondering where the 1s came from; at least I'm not. I am wondering why it displays: toctoc hihi u 1pupu zozo 1v 1tata 1coucou 1 instead of toctoc u 1hihi v 1pupu zozo 1coucou 1tata 1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo VS print : that's a cool behavior !
At 11:46 AM -0400 10/23/07, Robert Cummings wrote: On Tue, 2007-10-23 at 17:34 +0200, Julien Pauli wrote: ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); That's not cool, that's a mess. Why doe sit happen the way it does? First off, print() is a function so nesting functions means the innermost functions get processed first, this is why the output has mangled order. The 1's show up in the output because you're concatenating the return value of the print() function which is true for success. Cheers, Rob. -- Rob: Good call on the 1 return. Maybe this will help: http://www.webbytedd.com/bbb/echo-print/ Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo VS print : that's a cool behavior !
Hello everyone. We all know the difference between print and echo, but has someone ever tried to combine them together ?? Right, try this : ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); And guess the result ... Can someone explain it ? ( the result is : toctoc hihi u 1pupu zozo 1v 1tata 1coucou 1 ) Precedence. _ Windows Live Hotmail and Microsoft Office Outlook – together at last. Get it now. http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033
Re: [PHP] echo VS print : that's a cool behavior !
On Tue, 2007-10-23 at 11:54 -0400, Andrew Ballard wrote: On 10/23/07, Robert Cummings [EMAIL PROTECTED] wrote: On Tue, 2007-10-23 at 17:34 +0200, Julien Pauli wrote: ?php echo coucou . print('v ' . print('u ' . print('toctoc ') . 'hihi ') ) . 'tata ' . print('zozo ' . print('pupu ')); That's not cool, that's a mess. Why doe sit happen the way it does? First off, print() is a function so nesting functions means the innermost functions get processed first, this is why the output has mangled order. The 1's show up in the output because you're concatenating the return value of the print() function which is true for success. Agreed it's a mess, and I don't know why anyone would do it, but that's only part of the story. I don't think the OP was wondering where the 1s came from; at least I'm not. I am wondering why it displays: toctoc hihi u 1pupu zozo 1v 1tata 1coucou 1 instead of toctoc u 1hihi v 1pupu zozo 1coucou 1tata 1 My bad, print is not a function, and so: print( 'toctoc ' ).'hihi '; is equivalent to: print( 'tocktoc '.'hihi ' ); Parenthesis are option and only server to control precedence. But unlike echo print does return a value. Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo VS print : that's a cool behavior !
On 10/23/07, Robert Cummings [EMAIL PROTECTED] wrote: My bad, print is not a function, and so: print( 'toctoc ' ).'hihi '; is equivalent to: print( 'tocktoc '.'hihi ' ); Ah. I see. I knew they were optional, but I didn't know that when you include them PHP evaluates ('toctoc') before it passes the value off to print(). I just figured that with or without the parentheses it would pass 'toctoc' to print() and return a result that would be concatenated inline with the other values. I guess that's the part I didn't understand about the difference between a function and a language construct in PHP. As for the OP, I still don't know why anyone would even dream of creating code that does this other than to see what would happen if we :-) Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo VS print : that's a cool behavior !
That's just the case : too see what happens if I agree that anyone will never meet such a case in everydays' programming. ;-) 2007/10/23, Andrew Ballard [EMAIL PROTECTED]: On 10/23/07, Robert Cummings [EMAIL PROTECTED] wrote: My bad, print is not a function, and so: print( 'toctoc ' ).'hihi '; is equivalent to: print( 'tocktoc '.'hihi ' ); Ah. I see. I knew they were optional, but I didn't know that when you include them PHP evaluates ('toctoc') before it passes the value off to print(). I just figured that with or without the parentheses it would pass 'toctoc' to print() and return a result that would be concatenated inline with the other values. I guess that's the part I didn't understand about the difference between a function and a language construct in PHP. As for the OP, I still don't know why anyone would even dream of creating code that does this other than to see what would happen if we :-) Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
On 4/18/07, Richard Lynch [EMAIL PROTECTED] wrote: On Tue, April 17, 2007 1:40 am, Christian Haensel wrote: Whenever I see people put their code up for review, I realize they mostly use print instead of echo, while I am using echo 99% of the time. Actually, I can't even remember when I last used the regular print. There used to be a difference, but not really any more, I don't think. Or does print still not allow multiple arguments?... What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) I use echo, because I'm old, and got in the habit, back when print() was a function and echo was a language construct, and only echo let you have as many args with commas as you wanted. But there's no significant difference, as far as I know. There is a difference, echo is slightly faster. code used for benchmark: ? $start = microtime(TRUE); for ($i=0; $i10; ++$i) { print ABC; } echo sprintf(With print ($i): %0.3f\n,microtime(TRUE) - $start); $start = microtime(TRUE); for ($i=0; $i10; ++$i) { echo ABC; } echo sprintf(With echo ($i): %0.3f\n,microtime(TRUE) - $start); ? it displays 10 times ABC, first with the print command, and second with the echo command. Result: ABCABCABCsnip print (10): 0.085 ABCABCABCsnip echo (10): 0.076 It's not a lot, but since we are displaying data a lot, (most used function?) it will make a difference in really big scripts. Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
Tijnema ! wrote: On 4/18/07, Richard Lynch [EMAIL PROTECTED] wrote: On Tue, April 17, 2007 1:40 am, Christian Haensel wrote: Whenever I see people put their code up for review, I realize they mostly use print instead of echo, while I am using echo 99% of the time. Actually, I can't even remember when I last used the regular print. There used to be a difference, but not really any more, I don't think. Or does print still not allow multiple arguments?... What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) I use echo, because I'm old, and got in the habit, back when print() was a function and echo was a language construct, and only echo let you have as many args with commas as you wanted. But there's no significant difference, as far as I know. There is a difference, echo is slightly faster. code used for benchmark: ? $start = microtime(TRUE); for ($i=0; $i10; ++$i) { print ABC; } echo sprintf(With print ($i): %0.3f\n,microtime(TRUE) - $start); $start = microtime(TRUE); for ($i=0; $i10; ++$i) { echo ABC; } echo sprintf(With echo ($i): %0.3f\n,microtime(TRUE) - $start); ? it displays 10 times ABC, first with the print command, and second with the echo command. Result: ABCABCABCsnip print (10): 0.085 ABCABCABCsnip echo (10): 0.076 It's not a lot, but since we are displaying data a lot, (most used function?) it will make a difference in really big scripts. This has been covered before. The difference actually depends on how you're using it, rather than whether you use print or echo. For example, your benchmark shows echo to be slightly faster, but the the following script that I wrote last time this came up shows the opposite. The only difference is that you're outputting a literal whereas I'm printing a variable. http://dev.stut.net/phpspeed/ At the end of the day there are more important things to worry about, especially when you're talking in the region of 0.009 seconds per 100,000 calls it's not going to make anywhere near a significant difference to any script you write, even really really big ones scripts. To put it another way, you would need to make 10,000,000 calls for it to extend the runtime of your script by 1 second. Granted you might have a script that calls it 1000 times, meaning 10,000 requests to that script would waste 1 second. But unless you're getting twitter-like levels of traffic (they spike at over 11k hits a second) it's not worth worrying about, and I'm guessing (hoping) their devs probably wouldn't care either. Get over it and concentrate on the functionality and usability of your code rather than insignificant details like this. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
On 4/21/07, Stut [EMAIL PROTECTED] wrote: Tijnema ! wrote: On 4/18/07, Richard Lynch [EMAIL PROTECTED] wrote: On Tue, April 17, 2007 1:40 am, Christian Haensel wrote: Whenever I see people put their code up for review, I realize they mostly use print instead of echo, while I am using echo 99% of the time. Actually, I can't even remember when I last used the regular print. There used to be a difference, but not really any more, I don't think. Or does print still not allow multiple arguments?... What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) I use echo, because I'm old, and got in the habit, back when print() was a function and echo was a language construct, and only echo let you have as many args with commas as you wanted. But there's no significant difference, as far as I know. There is a difference, echo is slightly faster. code used for benchmark: ? $start = microtime(TRUE); for ($i=0; $i10; ++$i) { print ABC; } echo sprintf(With print ($i): %0.3f\n,microtime(TRUE) - $start); $start = microtime(TRUE); for ($i=0; $i10; ++$i) { echo ABC; } echo sprintf(With echo ($i): %0.3f\n,microtime(TRUE) - $start); ? it displays 10 times ABC, first with the print command, and second with the echo command. Result: ABCABCABCsnip print (10): 0.085 ABCABCABCsnip echo (10): 0.076 It's not a lot, but since we are displaying data a lot, (most used function?) it will make a difference in really big scripts. This has been covered before. The difference actually depends on how you're using it, rather than whether you use print or echo. For example, your benchmark shows echo to be slightly faster, but the the following script that I wrote last time this came up shows the opposite. The only difference is that you're outputting a literal whereas I'm printing a variable. http://dev.stut.net/phpspeed/ At the end of the day there are more important things to worry about, especially when you're talking in the region of 0.009 seconds per 100,000 calls it's not going to make anywhere near a significant difference to any script you write, even really really big ones scripts. To put it another way, you would need to make 10,000,000 calls for it to extend the runtime of your script by 1 second. Granted you might have a script that calls it 1000 times, meaning 10,000 requests to that script would waste 1 second. But unless you're getting twitter-like levels of traffic (they spike at over 11k hits a second) it's not worth worrying about, and I'm guessing (hoping) their devs probably wouldn't care either. Get over it and concentrate on the functionality and usability of your code rather than insignificant details like this. -Stut Interesting :) I see there's no big difference between echo and print, but that ?=$x? is faster :) I've learned (not only from this) that whatever you do in PHP is fast, and that you don't need to optimize your code for speed. Unless you're hitting 100k+ hits per hour. But even then it would only save you maybe one hour per year. Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
Tijnema ! wrote: On 4/21/07, Stut [EMAIL PROTECTED] wrote: Tijnema ! wrote: There is a difference, echo is slightly faster. code used for benchmark: ? $start = microtime(TRUE); for ($i=0; $i10; ++$i) { print ABC; } echo sprintf(With print ($i): %0.3f\n,microtime(TRUE) - $start); $start = microtime(TRUE); for ($i=0; $i10; ++$i) { echo ABC; } echo sprintf(With echo ($i): %0.3f\n,microtime(TRUE) - $start); ? it displays 10 times ABC, first with the print command, and second with the echo command. Result: ABCABCABCsnip print (10): 0.085 ABCABCABCsnip echo (10): 0.076 It's not a lot, but since we are displaying data a lot, (most used function?) it will make a difference in really big scripts. This has been covered before. The difference actually depends on how you're using it, rather than whether you use print or echo. For example, your benchmark shows echo to be slightly faster, but the the following script that I wrote last time this came up shows the opposite. The only difference is that you're outputting a literal whereas I'm printing a variable. http://dev.stut.net/phpspeed/ At the end of the day there are more important things to worry about, especially when you're talking in the region of 0.009 seconds per 100,000 calls it's not going to make anywhere near a significant difference to any script you write, even really really big ones scripts. To put it another way, you would need to make 10,000,000 calls for it to extend the runtime of your script by 1 second. Granted you might have a script that calls it 1000 times, meaning 10,000 requests to that script would waste 1 second. But unless you're getting twitter-like levels of traffic (they spike at over 11k hits a second) it's not worth worrying about, and I'm guessing (hoping) their devs probably wouldn't care either. Get over it and concentrate on the functionality and usability of your code rather than insignificant details like this. -Stut Interesting :) I see there's no big difference between echo and print, but that ?=$x? is faster :) I've learned (not only from this) that whatever you do in PHP is fast, and that you don't need to optimize your code for speed. Unless you're hitting 100k+ hits per hour. But even then it would only save you maybe one hour per year. I wouldn't go that far. It is definitely possible to write horribly inefficient code with PHP. Believe me, I've inherited enough crap code in my lifetime to testify to that. My point was simply that you need to look at the numbers from benchmarks in perspective, and when efficiency is concerned there's almost always far bigger gains to be made than 0.009 seconds per 100,000 calls to output something. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
On 4/21/07, Stut [EMAIL PROTECTED] wrote: Tijnema ! wrote: On 4/21/07, Stut [EMAIL PROTECTED] wrote: Tijnema ! wrote: There is a difference, echo is slightly faster. code used for benchmark: ? $start = microtime(TRUE); for ($i=0; $i10; ++$i) { print ABC; } echo sprintf(With print ($i): %0.3f\n,microtime(TRUE) - $start); $start = microtime(TRUE); for ($i=0; $i10; ++$i) { echo ABC; } echo sprintf(With echo ($i): %0.3f\n,microtime(TRUE) - $start); ? it displays 10 times ABC, first with the print command, and second with the echo command. Result: ABCABCABCsnip print (10): 0.085 ABCABCABCsnip echo (10): 0.076 It's not a lot, but since we are displaying data a lot, (most used function?) it will make a difference in really big scripts. This has been covered before. The difference actually depends on how you're using it, rather than whether you use print or echo. For example, your benchmark shows echo to be slightly faster, but the the following script that I wrote last time this came up shows the opposite. The only difference is that you're outputting a literal whereas I'm printing a variable. http://dev.stut.net/phpspeed/ At the end of the day there are more important things to worry about, especially when you're talking in the region of 0.009 seconds per 100,000 calls it's not going to make anywhere near a significant difference to any script you write, even really really big ones scripts. To put it another way, you would need to make 10,000,000 calls for it to extend the runtime of your script by 1 second. Granted you might have a script that calls it 1000 times, meaning 10,000 requests to that script would waste 1 second. But unless you're getting twitter-like levels of traffic (they spike at over 11k hits a second) it's not worth worrying about, and I'm guessing (hoping) their devs probably wouldn't care either. Get over it and concentrate on the functionality and usability of your code rather than insignificant details like this. -Stut Interesting :) I see there's no big difference between echo and print, but that ?=$x? is faster :) I've learned (not only from this) that whatever you do in PHP is fast, and that you don't need to optimize your code for speed. Unless you're hitting 100k+ hits per hour. But even then it would only save you maybe one hour per year. I wouldn't go that far. It is definitely possible to write horribly inefficient code with PHP. Believe me, I've inherited enough crap code in my lifetime to testify to that. My point was simply that you need to look at the numbers from benchmarks in perspective, and when efficiency is concerned there's almost always far bigger gains to be made than 0.009 seconds per 100,000 calls to output something. -Stut But what else would you use a lot in your code? all commonly used things (like while, if, echo, etc) are just (nearly) as fast as their alternatives (for, print, etc). Other functions (like file/stream) might be some performance difference, but you probably use this only a few times in your script. So there's not a bigger performance difference then when optimizing echo/print. Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
Tijnema ! wrote: But what else would you use a lot in your code? all commonly used things (like while, if, echo, etc) are just (nearly) as fast as their alternatives (for, print, etc). Other functions (like file/stream) might be some performance difference, but you probably use this only a few times in your script. So there's not a bigger performance difference then when optimizing echo/print. Get your head out of the details. Try file-based caching against DB access. Or SQL query optimisation. Or even server configuration tuning. All these things and others on the same level are far more worthy of your time. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
On 4/22/07, Stut [EMAIL PROTECTED] wrote: Tijnema ! wrote: But what else would you use a lot in your code? all commonly used things (like while, if, echo, etc) are just (nearly) as fast as their alternatives (for, print, etc). Other functions (like file/stream) might be some performance difference, but you probably use this only a few times in your script. So there's not a bigger performance difference then when optimizing echo/print. Get your head out of the details. Try file-based caching against DB access. And compare that with RAM caching ;) Or SQL query optimisation. Or even server configuration tuning. All these things and others on the same level are far more worthy of your time. -Stut So, optimizing is useless :P I see no point in doing it, even more when it's only for personal usage. The time used for writing optimized code is probably far more then the time you save by running optimized code. :) Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
Tijnema ! wrote: On 4/22/07, Stut [EMAIL PROTECTED] wrote: Tijnema ! wrote: But what else would you use a lot in your code? all commonly used things (like while, if, echo, etc) are just (nearly) as fast as their alternatives (for, print, etc). Other functions (like file/stream) might be some performance difference, but you probably use this only a few times in your script. So there's not a bigger performance difference then when optimizing echo/print. Get your head out of the details. Try file-based caching against DB access. And compare that with RAM caching ;) Or SQL query optimisation. Or even server configuration tuning. All these things and others on the same level are far more worthy of your time. -Stut So, optimizing is useless :P I see no point in doing it, even more when it's only for personal usage. The time used for writing optimized code is probably far more then the time you save by running optimized code. :) I hope that smiley means you're joking. Optimising is not useless, and I've never said it is. However, you have to do so where it's going to have the biggest impact. What I'm basically saying is you should be optimising logic before even thinking about whether you're using the most optimised functions. Are you sure that your code doesn't do anything it doesn't need to? Do you do a whole load of initialisation for each request that could be cached in some way? Is every part of that initialisation needed for every page request, or should it be doing different things on different pages. IMHO, the kind of developer that gets hung up on details like echo or print is one that is unlikely to accomplish a lot in any given day. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
On Sat, April 21, 2007 5:20 pm, Tijnema ! wrote: But what else would you use a lot in your code? all commonly used things (like while, if, echo, etc) are just (nearly) as fast as their alternatives (for, print, etc). Other functions (like file/stream) might be some performance difference, but you probably use this only a few times in your script. So there's not a bigger performance difference then when optimizing echo/print. You use valgrind/callgrind and find out where your bottlenecks are and optimize those. You also benchmark your non-PHP stuff which is often the bottleneck in the first place. Optimizing random bits of code that aren't your bottleneck is just wasting your most precious resource: YOUR TIME! -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] echo or print ?
Good morning fellow coders I've been working with PHP for a little over 5 years now, and it even got me a cute office and a good salary... but even though I can make a living off of it, I am still wondering about a few little things. Whenever I see people put their code up for review, I realize they mostly use print instead of echo, while I am using echo 99% of the time. Actually, I can't even remember when I last used the regular print. What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) All the best! Chris Christian Haensel /voodoo.css #GeorgeWBush { position:absolute; bottom:-6ft; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) print returns a result, echo doesn't. This makes echo slightly faster than print, but I doubt theres any significant speed improvement using echo instead of print. I use echo, but thats just because its a habit. -- Regards, Clive. {No electrons were harmed in the creation, transmission or reading of this email. However, many were excited and some may well have enjoyed the experience.} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
Me too. I use echo. Print is a function. There's no significant difference between them. My advice: choose one, and stick with it. On 4/16/07, clive [EMAIL PROTECTED] wrote: What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) print returns a result, echo doesn't. This makes echo slightly faster than print, but I doubt theres any significant speed improvement using echo instead of print. I use echo, but thats just because its a habit. -- Regards, Clive. {No electrons were harmed in the creation, transmission or reading of this email. However, many were excited and some may well have enjoyed the experience.} -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
On 4/17/07, Christian Haensel [EMAIL PROTECTED] wrote: Good morning fellow coders I've been working with PHP for a little over 5 years now, and it even got me a cute office and a good salary... but even though I can make a living off of it, I am still wondering about a few little things. Whenever I see people put their code up for review, I realize they mostly use print instead of echo, while I am using echo 99% of the time. Actually, I can't even remember when I last used the regular print. What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) There is a link in the manual about the difference between those two: http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
Thanks mate, that clarifies that. And now I know why I use echo all the time *g* Have a great day,... greetings from sunny germany :o) Chris - Original Message - From: Dimiter Ivanov [EMAIL PROTECTED] To: Christian Haensel [EMAIL PROTECTED] Cc: php-general@lists.php.net Sent: Tuesday, April 17, 2007 9:48 AM Subject: Re: [PHP] echo or print ? On 4/17/07, Christian Haensel [EMAIL PROTECTED] wrote: Good morning fellow coders I've been working with PHP for a little over 5 years now, and it even got me a cute office and a good salary... but even though I can make a living off of it, I am still wondering about a few little things. Whenever I see people put their code up for review, I realize they mostly use print instead of echo, while I am using echo 99% of the time. Actually, I can't even remember when I last used the regular print. What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) There is a link in the manual about the difference between those two: http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print ?
On Tue, April 17, 2007 1:40 am, Christian Haensel wrote: Whenever I see people put their code up for review, I realize they mostly use print instead of echo, while I am using echo 99% of the time. Actually, I can't even remember when I last used the regular print. There used to be a difference, but not really any more, I don't think. Or does print still not allow multiple arguments?... What do you guys use, and what is the advantage (if ther is any) of print over echo? And I am not talking about print_r or anything, just the regular print. :o) I use echo, because I'm old, and got in the habit, back when print() was a function and echo was a language construct, and only echo let you have as many args with commas as you wanted. But there's no significant difference, as far as I know. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
Eugene, et al -- ...and then Eugene Lee said... % % p class=tonue-in-cheek % % Also, the letter 'e' is smaller than 'p', so ASCII-based function % lookups will be faster as well. Most of these speed increases can't be noticed in a small script, where the end is within a few lines, but echo() really works well in larger scripts where the end is far away. In addition, print() only sort of works well in the near case and doesn't work at all in the far case (as demonstrated when trying to throw something printed, such as a book). Finally, echo()ed statements always remain in the proper order, but throwing a bunch of print()s will just get you a big mess on the floor requiring an intelligent sort() to clean up -- and you know how tough it can be to write a quick sort() algorithm! % % /p HTH HAND ;-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, Science and Health http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg! pgp0.pgp Description: PGP signature
RE: [PHP] echo or print
David T-G wrote: Eugene, et al -- ...and then Eugene Lee said... % % p class=tonue-in-cheek % % Also, the letter 'e' is smaller than 'p', so ASCII-based function % lookups will be faster as well. Most of these speed increases can't be noticed in a small script, where the end is within a few lines, but echo() really works well in larger scripts where the end is far away. In addition, print() only sort of works well in the near case and doesn't work at all in the far case (as demonstrated when trying to throw something printed, such as a book). Finally, echo()ed statements always remain in the proper order, but throwing a bunch of print()s will just get you a big mess on the floor requiring an intelligent sort() to clean up -- and you know how tough it can be to write a quick sort() algorithm! % % /p HTH HAND ;-D Guys, Jay asked a serious question (I think). Anyways, let's take this one step further to something that I've really been wondering about. (.. long bunch of HTML ..) Jay asked ?=$Question?, then Tom said ? echo $Answer; ?. ?php print 'Meanwhile a lot of others read it including '.$Strangers[0].', '.$Strangers[2].', '.$Strangers[3].' and '.$Strangers[4].'.\n; echo After a short while, among others, $Kirk[firstname] {$Kirk[lastname]} also said his things.; ? Point is, which of the inline printing style is preferred by you guyes. I tend to use ?=$Var? a lot, since it reads easier but get into struggles with myself when I do that multiple times in a row. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo or print
Wouter van Vliet mailto:[EMAIL PROTECTED] on Friday, November 21, 2003 10:55 AM said: Point is, which of the inline printing style is preferred by you guyes. I tend to use ?=$Var? a lot, since it reads easier but get into struggles with myself when I do that multiple times in a row. Because of this I usually do the following: echo phere is some text with a $variable in it.br/\n .And this is another like of text with a $variable1 in it.br/\n .And so on...br/\n .And so forth./p\n; I also prefer ?= $variable ? to ?php echo $variable; ? except that for the sake of cross-system compatibility* I now choose to do ?php echo $variable; ?. Chris. * What I mean by that is if I give my code to someone else I want it to work with as few changes as possible. Some php installs don't have ? ? turned on (short tags?). -- Don't like reformatting your Outlook replies? Now there's relief! http://home.in.tum.de/~jain/software/outlook-quotefix/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo or print
Chris W. Parker wrote: Wouter van Vliet mailto:[EMAIL PROTECTED] on Friday, November 21, 2003 10:55 AM said: Point is, which of the inline printing style is preferred by you guyes. I tend to use ?=$Var? a lot, since it reads easier but get into struggles with myself when I do that multiple times in a row. Because of this I usually do the following: echo phere is some text with a $variable in it.br/\n .And this is another like of text with a $variable1 in it.br/\n .And so on...br/\n .And so forth./p\n; I also prefer ?= $variable ? to ?php echo $variable; ? except that for the sake of cross-system compatibility* I now choose to do ?php echo $variable; ?. Chris. * What I mean by that is if I give my code to someone else I want it to work with as few changes as possible. Some php installs don't have ? ? turned on (short tags?). Well, there is an eye opener. I always thought that the ?=$Var? printing style was not influenced by short_open_tag, but now I did a test to be sure about it and it turned out it does.. quick test 1 ?php 2 echo 'ini setting short_open_tag: '.ini_get('short_open_tag'); 3 ? 4 5 Long open tags: ?php print 'OK'; ? 6 Short open tags ? print 'OK'; ? 7 Short print style ?='OK'? output short_open_tags=On ini setting short_open_tag: 1 Long open tags: OK Short open tags OK Short print style OK /output output short_open_tags=Off ini setting short_open_tag: Long open tags: OK Short open tags ? print 'OK'; ? Short print style ?='OK'? /output /quick_test Thanks! Wouter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo or print
On Fri, 21 Nov 2003, Wouter van Vliet wrote: Point is, which of the inline printing style is preferred by you guyes. I tend to use ?=$Var? a lot, since it reads easier but get into struggles with myself when I do that multiple times in a row. Ultimately I think you'd want to be doing very little of any, if you're working with more than a basic, one-page script. Even if you are (gulp) generating your HTML output within functions, it seems better to be returning that back to some level where there are only a couple of echo/prints necessary.. Think output layer... -- Kelly Hallman // Ultrafancy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo or print
--- Chris W. Parker [EMAIL PROTECTED] wrote: I also prefer ?= $variable ? to ?php echo $variable; ? except that for the sake of cross-system compatibility* I now choose to do ?php echo $variable; ?. I think explicitly using echo is much more readable. While it may be obvious to many what ?= does, it is one more little thing that might seem like magic to someone else. The less of that type of syntax, the better, in my opinion. If you want magic syntax, there's Perl. It has a lot of great shortcuts, if you're familiar with the syntax. With PHP, most things you don't understand are easy to look up. I'd rather search for echo than ?= if I was new to PHP. * What I mean by that is if I give my code to someone else I want it to work with as few changes as possible. Some php installs don't have ? ? turned on (short tags?). Right, plus I don't think ?php= will work (you might have been suggesting this). This was discussed on the internals list a year or two ago, and it was voted down. Chris = Chris Shiflett - http://shiflett.org/ PHP Security Handbook Coming mid-2004 HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo or print
Kelly Hallman wrote: On Fri, 21 Nov 2003, Wouter van Vliet wrote: Point is, which of the inline printing style is preferred by you guyes. I tend to use ?=$Var? a lot, since it reads easier but get into struggles with myself when I do that multiple times in a row. Ultimately I think you'd want to be doing very little of any, if you're working with more than a basic, one-page script. Even if you are (gulp) generating your HTML output within functions, it seems better to be returning that back to some level where there are only a couple of echo/prints necessary.. Think output layer... Yep, that's how I usually think. For projects set up by me I usually put as many as none logic into the output scripts, and just have them echo some values. For example, on a news-page I call a function which returns an array with (non-layout) specific values. And it are those values that make it their way to ?=$News['Title']? and stuff like that. Sometimes though, I find myself in a situation wheren I am merely changing someone else's code and their approach isn't always (=usually not) like this at all. But this is not really what the topic is about ;) Chris Shiflett wrote: --- Chris W. Parker [EMAIL PROTECTED] wrote: I also prefer ?= $variable ? to ?php echo $variable; ? except that for the sake of cross-system compatibility* I now choose to do ?php echo $variable; ?. I think explicitly using echo is much more readable. While it may be obvious to many what ?= does, it is one more little thing that might seem like magic to someone else. The less of that type of syntax, the better, in my opinion. If you want magic syntax, there's Perl. It has a lot of great shortcuts, if you're familiar with the syntax. With PHP, most things you don't understand are easy to look up. I'd rather search for echo than ?= if I was new to PHP. I disagree on that. ?php echo $Var; ? is much longer and causes lines to wrap and stuff. That is what I find unreadable. Yes, ?=$Var? looks a bit like magic, but no more than Harry Potter magic. Not like Gdanalf magic or anything. If you want Gandalf magic, I can give you some: ?=($WhoseMagic=='Tolkien'?'Gandalf':'Harry Potter')? Still I care more about compactness than the level of magic. Good programmers/scripters could read my code, bad ones can't. This is called natural selection, since bad scripters should stay out of my code. :P:P * What I mean by that is if I give my code to someone else I want it to work with as few changes as possible. Some php installs don't have ? ? turned on (short tags?). Right, plus I don't think ?php= will work (you might have been suggesting this). This was discussed on the internals list a year or two ago, and it was voted down. Too bad, is anything known about maybe implementing a new directive next to short_open_tags .. Something like short_echo_style, so that you won't be allowed to open tags the short way, while still being able to echo in short style. I see them as two different entities. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] echo or print
Hi, Saturday, November 22, 2003, 4:55:05 AM, you wrote: WvV David T-G wrote: WvV Guys, Jay asked a serious question (I think). Anyways, let's take this one WvV step further to something that I've really been wondering about. WvV (.. long bunch of HTML ..) WvV Jay asked ?=$Question?, then Tom said ? echo $Answer; ?. ?php WvV print 'Meanwhile a lot of others read it including '.$Strangers[0].', WvV '.$Strangers[2].', '.$Strangers[3].' and '.$Strangers[4].'.\n; WvV echo After a short while, among others, $Kirk[firstname] {$Kirk[lastname]} WvV also said his things.; ? WvV Point is, which of the inline printing style is preferred by you guyes. I WvV tend to use ?=$Var? a lot, since it reads easier but get into struggles WvV with myself when I do that multiple times in a row. The first time I ever used print was in the example I gave above so echo does everything I have needed till now. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
On Fri, Nov 21, 2003 at 07:55:05PM +0100, Wouter van Vliet wrote: : : (.. long bunch of HTML ..) : Jay asked ?=$Question?, then Tom said ? echo $Answer; ?. ?php I don't like this because it doesn't protect your content from being misinterpreted. It should be more like: Jay asked ?php echo htmlentities($Question); ?, then... Of course you could call htmlentities() on all of your variables in a previouw block. But then you cannot use the variables again unless you undo it with html_entity_decode(). It's a bit of a mess. Also, I find inlining to be less flexible and less extensible than some kind of template system. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
Rasmus Lerdorf 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 1 That 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. -- Jon Kriek www.phpfreaks.com Wouter Van Vliet wrote: Chris W. Parker wrote: Wouter van Vliet mailto:[EMAIL PROTECTED] on Friday, November 21, 2003 10:55 AM said: Point is, which of the inline printing style is preferred by you guyes. I tend to use ?=$Var? a lot, since it reads easier but get into struggles with myself when I do that multiple times in a row. Because of this I usually do the following: echo phere is some text with a $variable in it.br/\n .And this is another like of text with a $variable1 in it.br/\n .And so on...br/\n .And so forth./p\n; I also prefer ?= $variable ? to ?php echo $variable; ? except that for the sake of cross-system compatibility* I now choose to do ?php echo $variable; ?. Chris. * What I mean by that is if I give my code to someone else I want it to work with as few changes as possible. Some php installs don't have ? ? turned on (short tags?). Well, there is an eye opener. I always thought that the ?=$Var? printing style was not influenced by short_open_tag, but now I did a test to be sure about it and it turned out it does.. quick test 1 ?php 2 echo 'ini setting short_open_tag: '.ini_get('short_open_tag'); 3 ? 4 5 Long open tags: ?php print 'OK'; ? 6 Short open tags ? print 'OK'; ? 7 Short print style ?='OK'? output short_open_tags=On ini setting short_open_tag: 1 Long open tags: OK Short open tags OK Short print style OK /output output short_open_tags=Off ini setting short_open_tag: Long open tags: OK Short open tags ? print 'OK'; ? Short print style ?='OK'? /output /quick_test Thanks! Wouter -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
* Thus wrote Wouter van Vliet ([EMAIL PROTECTED]): Point is, which of the inline printing style is preferred by you guyes. I tend to use ?=$Var? a lot, since it reads easier but get into struggles with myself when I do that multiple times in a row. 1. Turn off short_open_tags 2. Turn off asp_tags 3. use ?php echo $Var? Curt -- My PHP key is worn out PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
On Sat, 2003-11-22 at 00:13, Curt Zirzow wrote: * Thus wrote Wouter van Vliet ([EMAIL PROTECTED]): Point is, which of the inline printing style is preferred by you guyes. I tend to use ?=$Var? a lot, since it reads easier but get into struggles with myself when I do that multiple times in a row. 1. Turn off short_open_tags 2. Turn off asp_tags 3. use ?php echo $Var? Personally, I don't use inline since I prefer templating, but when i do this kind of code for other projects where I don't get the choice to use a templating system, then I use the above style also. I find ?=$Var? to be cryptic even if shorter. Besides I'm all for code consistency, if I'm going to break into PHP mode for multiple lines, then I do the same for a single line. Cheers, Rob. -- .. | InterJinn Application Framework - http://www.interjinn.com | :: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] echo or print
when should i use echo ' '; vs. print ' '; Jay Fitzgerald, Design Director - Certified Professional Webmaster (CPW-A) - Certified Professional Web Designer (CPWDS-A) - Certified Professional Web Developer (CPWDV-A) - Certified E-Commerce Manager (CECM-A) - Certified Small Business Web Consultant (CWCSB-A) Bayou Internet - http://www.bayou.com Toll Free: 888.30.BAYOU (22968) Vox: 318.338.2034 / Fax: 318.338.2506 E-Mail: [EMAIL PROTECTED] ICQ: 38823829 / AIM: bayoujf / MSN: bayoujf / Yahoo: bayoujf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
Hi, Friday, November 21, 2003, 12:37:50 AM, you wrote: JF when should i use echo ' '; vs. print ' '; JF JF Jay Fitzgerald, Design Director JF - Certified Professional Webmaster (CPW-A) JF - Certified Professional Web Designer (CPWDS-A) JF - Certified Professional Web Developer (CPWDV-A) JF - Certified E-Commerce Manager (CECM-A) JF - Certified Small Business Web Consultant (CWCSB-A) JF Bayou Internet - http://www.bayou.com JF Toll Free: 888.30.BAYOU (22968) JF Vox: 318.338.2034 / Fax: 318.338.2506 JF E-Mail: [EMAIL PROTECTED] JF ICQ: 38823829 / AIM: bayoujf / MSN: bayoujf / Yahoo: bayoujf JF There is no real difference in common usage, print returns true always so you can use it in weird situations otherwise echo is a tiny bit faster. You can do stuff like this if(isset($_GET['name'] print('DEBUG: received name set to '.$_GET['name'].br\n)){ //normal processing here } -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
Jay Fitzgerald wrote: when should i use echo ' '; vs. print ' '; You should always use echo. It'll make a significant performance increase in your scripts as it's only four letters instead of five. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] echo or print
when should i use echo ' '; vs. print ' '; Here's a link listed in the manual at http://www.php.net/manual/en/function.print.php http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40 Kirk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
Tom Rogers wrote: Hi, Friday, November 21, 2003, 12:37:50 AM, you wrote: JF when should i use echo ' '; vs. print ' '; JF JF Jay Fitzgerald, Design Director JF - Certified Professional Webmaster (CPW-A) JF - Certified Professional Web Designer (CPWDS-A) JF - Certified Professional Web Developer (CPWDV-A) JF - Certified E-Commerce Manager (CECM-A) JF - Certified Small Business Web Consultant (CWCSB-A) JF Bayou Internet - http://www.bayou.com JF Toll Free: 888.30.BAYOU (22968) JF Vox: 318.338.2034 / Fax: 318.338.2506 JF E-Mail: [EMAIL PROTECTED] JF ICQ: 38823829 / AIM: bayoujf / MSN: bayoujf / Yahoo: bayoujf JF Jay, can you please reduce your signature? Because it leads to unnecessary fluff when people don't trim posts. Tom, please trim your replies. We don't need to see the same signature twice (especially if its as grand as Jay's). Where is that newbie email? -- Burhan Khalid phplist[at]meidomus[dot]com http://www.meidomus.com --- Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo or print
On Thu, Nov 20, 2003 at 12:36:42PM -0500, John W. Holmes wrote: : : Jay Fitzgerald wrote: : : when should i use echo ' '; vs. print ' '; : : You should always use echo. It'll make a significant performance : increase in your scripts as it's only four letters instead of five. p class=tonue-in-cheek Also, the letter 'e' is smaller than 'p', so ASCII-based function lookups will be faster as well. /p -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] echo vs. print() performance?
I have a way of performance logging anything with php. Let me know what type of performance data you would like to see and I will do my best to get the data ready rather quickly. I will gather the data that I have collect over the past few months. It is a performance log of every part of php that my site uses. I will try an get that data together by the first of next week. it will show microsecond time lines of include(), requires(), print() echo, ?=?, and other related functions. Lets me know what you would like to see. Jim Lucas - Original Message - From: Jack Dempsey [EMAIL PROTECTED] To: Jon Niola [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Thursday, December 13, 2001 11:50 PM Subject: Re: [PHP] echo vs. print() performance? not as a criticism, but this is among the top 10 questions asked ...or used to be for a while...anyway, there's tons of info on the mailing lists, marc.theaimsgroup.com the short answer is that echo is SLIGHTLY faster being a language construct rather than a function...then again, i believe i remember someone proving the opposite...in general, you'll never notice a differenece between the two... Jon Niola wrote: Someone on this list once mentioned a performance difference between using echo and print(). Is there any evidence to back this up? I am really curious to see if it would make a difference to use one over the other. --Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] echo vs. print() performance?
Someone on this list once mentioned a performance difference between using echo and print(). Is there any evidence to back this up? I am really curious to see if it would make a difference to use one over the other. --Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] echo vs. print() performance?
not as a criticism, but this is among the top 10 questions asked ...or used to be for a while...anyway, there's tons of info on the mailing lists, marc.theaimsgroup.com the short answer is that echo is SLIGHTLY faster being a language construct rather than a function...then again, i believe i remember someone proving the opposite...in general, you'll never notice a differenece between the two... Jon Niola wrote: Someone on this list once mentioned a performance difference between using echo and print(). Is there any evidence to back this up? I am really curious to see if it would make a difference to use one over the other. --Jon -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] echo vs print (was echo vs printf)
Ummm. I am not sure about either having a return value... but print you have $points points; and echo you have $points points; have identical output. You can drop a variable into an echo statement with no problem Sheridan - Original Message - From: Steve Brett [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, July 16, 2001 10:48 AM Subject: Re: [PHP] echo vs printf i seem to remember reading somewhere that print acts like (is) a function, presumably returning false if it cannot print to screen, whereas echo just dumps it. also you can drop vars in print like print you have $points points; whereas to echo it you'd have to concatenate the string. Steve Don Read [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... On 16-Jul-01 brother wrote: Why should I use printf instead of echo and vice versa? printf print-formated $a=12.3456; echo $a, 'BR'; printf('%1.2fBR', $a); 12.3456BR 12.34BR As for today I use printf mostly but I don't know why. You prolly mean print; There may be some minor differences from echo, but i've never seen 'em. (i think they threw print in PHP to keep JAPHs happy). Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] echo vs print
Maxim Maletsky wrote: Anyway, "?php" , "?" are quite same too, except that php3 used to have "?php" while older versions use mainly "?", this is just about compatibility. I believe ?php is needed if you want your scripts to be valid XML. Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] echo vs print
I have "Profession PHP Programming" and I see that echo() and print() are used alomst interchangeably. When should each one be used? Also, I see "?php" and "?" used. Is there a preference? And how about "};" versus "}" to end a block? I see both. Todd -- Todd Cary Ariste Software [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] echo vs print
From recent posts: http://www.zend.com/zend/tut/using-strings.php also see the doc for print in the PHP manual: http://www.php.net/manual/en/function.print.php Jeff Oien I have "Profession PHP Programming" and I see that echo() and print() are used alomst interchangeably. When should each one be used? Also, I see "?php" and "?" used. Is there a preference? And how about "};" versus "}" to end a block? I see both. Todd -- Todd Cary Ariste Software [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] echo vs print
On Thu, 8 Feb 2001, Todd Cary wrote: I have "Profession PHP Programming" and I see that echo() and print() are used alomst interchangeably. When should each one be used? What is the difference between echo and print ? - http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/41 Also, I see "?php" and "?" used. Is there a preference? ? is a short tag, ?php is not. ?php will always work, everywhere, always. This is what should be used. ? will most likely always work wherever your script may travel but keep in mind, this setting can be turned off. See : http://www.php.net/manual/en/configuration.php#ini.short-open-tag And how about "};" versus "}" to end a block? I see both. Don't do }; as it looks funny. Btw, I've never seen }; used within the manual. Regards, Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Echo and Print
As I understand it, echo is somewhat of an language construct and print is a function. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, January 26, 2001 11:37 AM To: [EMAIL PROTECTED] Subject: [PHP] Echo and Print I know it is a kind of stupid question but I was trying to figure out the difference between "Echo" and "Print" and I didn't find it...Could anybody explain that to me?? Thank you Felipe Lopes MailBR - O e-mail do Brasil -- http://www.mailbr.com.br Faa j o seu. gratuito!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Echo and Print
Hi, I cut paste this from an earlier e-mail from this list, hope it helps: - The print() function returns a boolean indicating the status of the call. If the write was successful, print() returns 1. If not, it returns 0. This can be used to detect when the client has closed the connection, and appropriate measures taken. The builtin echo does not provide this same service. This may be handy for you, though there's probably a lot more to it. HTH Jon - Regards, Sumarlidi Einar Dadason SED - Graphic Design -- Phone: (+354) 4615501 Mobile: (+354) 8960376 Fax: (+354) 4615503 E-mail: [EMAIL PROTECTED] Homepage:www.sed.is - New Homepage! -- -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: 26. janar 2001 11:37 To: [EMAIL PROTECTED] Subject: [PHP] Echo and Print I know it is a kind of stupid question but I was trying to figure out the difference between "Echo" and "Print" and I didn't find it...Could anybody explain that to me?? Thank you Felipe Lopes MailBR - O e-mail do Brasil -- http://www.mailbr.com.br Faa j o seu. gratuito!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Echo and Print
print is a function where u can add html tags like print("brb hello $name") however echo is a command where we can't include html tags ! echo "hello".$name From: Philip Olson [EMAIL PROTECTED] To: [EMAIL PROTECTED] CC: [EMAIL PROTECTED] Subject: Re: [PHP] Echo and Print Date: Fri, 26 Jan 2001 18:29:27 + (GMT) What is the difference between echo and print ? --- http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/41 Philip On 26 xxx -1 [EMAIL PROTECTED] wrote: I know it is a kind of stupid question but I was trying to figure out the difference between "Echo" and "Print" and I didn't find it...Could anybody explain that to me?? Thank you Felipe Lopes MailBR - O e-mail do Brasil -- http://www.mailbr.com.br Faça já o seu. É gratuito!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] _ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Echo and Print
print is a function where u can add html tags like print("brb hello $name") however echo is a command where we can't include html tags ! echo "hello".$name This is VERY incorrect, please read this : What is the difference between echo and print ? --- http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/41 And then try this : $name = 'fred'; echo "brb$name/bbr" . $name; print "brb$name/bbr" . $name Then try this : echo 'sup','yo'; print 'sup','yo'; // Parse error! But that FAQ explains it better then I can so ... Philip On 26 xxx -1 [EMAIL PROTECTED] wrote: I know it is a kind of stupid question but I was trying to figure out the difference between "Echo" and "Print" and I didn't find it...Could anybody explain that to me?? Thank you Felipe Lopes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]