Haunted Dawg Posted January 31, 2009 Share Posted January 31, 2009 I see alot of people using echo sprintf("%s", 'blah?'); But i ask my self this. Why make use of 2 function's when instead use 1? printf("%s", 'blah?'); Could some one with more knowledge please let me know. Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted January 31, 2009 Share Posted January 31, 2009 Re: Debate Look at the source to PHP... Both functions go through the low level standard libc library, so the effect is identical. Speedwise, if you are concerned, then I'd suggest your need to rethink your ideas. I have (IIRC) one print, one and one echo at the maximum on any page. Benchmarking is pointless, as almost any system you will create will be cached, so it (for me) comes down to the level of code clarity, something that is sadly lacking here. Take your pick... echo is a function (yes, I know it doesn't look like it, but look at the LALR parser of PHP), printf and sprintf both call the same inbuilt routines, so the question becomes, just how does echo display information versus printf ... perhaps they use the same mechanism. Go find out. The source has all the answers. Quote Link to comment Share on other sites More sharing options...
Rainbow Posted February 19, 2009 Share Posted February 19, 2009 Re: Debate Speedwise, if you are concerned, then I'd suggest your need to rethink your ideas. Speed wise it should be irrelevant which one you use... echo is only marginally faster since it doesn't set a return value... There is a difference in the expression of the command. I think that print can be used as part of a more complex expression where echo cannot. print() can only take one parameter... whereas, echo without parentheses can take multiple parameters, which get concatenated. So for example echo "and a ", 1, 2, 3; // comma-separated without parentheses echo ("and a 123"); // just one parameter with parentheses print() can only take one parameter: print ("and a 123"); print "and a 123"; Or am I wrong? Quote Link to comment Share on other sites More sharing options...
POG1 Posted February 19, 2009 Share Posted February 19, 2009 Re: Debate why not just output that string in html instead.. Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted February 20, 2009 Share Posted February 20, 2009 Re: Debate [quote author=Rainbow link=topic=27759.msg128120#msg128120 Or am I wrong? Yes Quote Link to comment Share on other sites More sharing options...
POG1 Posted February 20, 2009 Share Posted February 20, 2009 Re: Debate Speedwise, if you are concerned, then I'd suggest your need to rethink your ideas. Speed wise it should be irrelevant which one you use... echo is only marginally faster since it doesn't set a return value... There is a difference in the expression of the command. I think that print can be used as part of a more complex expression where echo cannot. print() can only take one parameter... whereas, echo without parentheses can take multiple parameters, which get concatenated. So for example echo "and a ", 1, 2, 3; // comma-separated without parentheses echo ("and a 123"); // just one parameter with parentheses print() can only take one parameter: print ("and a 123"); print "and a 123"; Or am I wrong? Print can be used as a function whereas echo cannot. Quote Link to comment Share on other sites More sharing options...
Karlos Posted February 20, 2009 Share Posted February 20, 2009 Re: Debate Speedwise on my viewuser.php http://cursed-islands.com/Karlos/Files/echo sprintf() vs printf().php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.