echo, printf or print
Moderator: General Moderators
- caseymanus
- Forum Commoner
- Posts: 34
- Joined: Wed Nov 20, 2002 10:32 pm
- Contact:
echo, printf or print
Comming from a C++ world, I tend to use printf alot more than plain print or echo,....are there any situations in which you guys think its better to use echo or print? Is there any performance gain or hit?
- Johnm
- Forum Contributor
- Posts: 344
- Joined: Mon May 13, 2002 12:05 pm
- Location: Michigan, USA
- Contact:
Here is a previous thread concerning this.
I personally use echo though.
John M
http://forums.devnetwork.net/viewtopic.php?t=2960
I personally use echo though.
John M
http://forums.devnetwork.net/viewtopic.php?t=2960
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Handily there was a bit about this in an article on zend.com:
http://www.zend.com/zend/art/mistake.php#Heading4
Basically, use printf() when you need to format the output before displaying it - probably of most use when outputting numbers. Use print() or echo() the rest of the time 'cause it's faster. echo() tends to be used more than print() not because there is any real difference between them but more because echo() has one less character to type
.
Mac
http://www.zend.com/zend/art/mistake.php#Heading4
Basically, use printf() when you need to format the output before displaying it - probably of most use when outputting numbers. Use print() or echo() the rest of the time 'cause it's faster. echo() tends to be used more than print() not because there is any real difference between them but more because echo() has one less character to type
Mac
A couple of things that Twig didn't mention, much to my suprise as she usually covers everything; print() will return true or false as opposed to echo() wich doesn't. This may be desireable to you. Another thing to keep in mind. If you are dumping large bits of HTML to the screen....
is faster than
!
And uhh...., Jason. There seems to be a problem of some sort. Why is it that in the first example above, the php close tag doesn't show up?
Cheers,
BDKR
Code: Select all
<?php
# Some code here
/* --- code --- */
# Now exit php mode
?>
<html>
<head>
<title>(Shameless Plug) Maximum Galoots Atypical PHP Soap Box</title>
</head>
</html>
<?phpCode: Select all
echo <html>;
echo <head>;
echo <title>(Shameless Plug) Maximum Galoots Atypical PHP Soap Box</title>;
echo </head>;
echo </html>;And uhh...., Jason. There seems to be a problem of some sort. Why is it that in the first example above, the php close tag doesn't show up?
Cheers,
BDKR