CHAMAVELI Posted July 25, 2008 Share Posted July 25, 2008 Hey guys, I'm new to PHP so I don't know the answer to this, so I know the echo is faster than print, so if I replace print with echo in my scripts will anything be affected that I should know about or is having echo completely safe? Quote Link to comment Share on other sites More sharing options...
Floydian Posted July 25, 2008 Share Posted July 25, 2008 Re: Simple Question In all seriousness, you'd be wasting your time making that replacement. I think people that are new to coding are very keen to make things as efficient as they can. But when you get to be an old and jaded coder like me, you'll be far less likely to feel the urge to implement such changes as a print to echo replacement because you'll have realized long ago that it would make virtually no difference and that your time would be better spent elsewhere doing some real optimization. ;) Or in the case of someone new to coding, time would be better spent writing new code or studying. Quote Link to comment Share on other sites More sharing options...
CHAMAVELI Posted July 26, 2008 Author Share Posted July 26, 2008 Re: Simple Question Ok thanks for the help. I won't be changing the codes as they will be useless waste of time. Quote Link to comment Share on other sites More sharing options...
Floydian Posted July 26, 2008 Share Posted July 26, 2008 Re: Simple Question That's what's up ;) I've worked with a lot of code that has print in it. Almost half of cove of pirates.com uses print. But anything new gets all echo's ') Good luck! Quote Link to comment Share on other sites More sharing options...
topmorpg Posted July 26, 2008 Share Posted July 26, 2008 Re: Simple Question the speed differences between print and echo are so minute you wont see a difference. http://www.learnphponline.com/php-basic ... o-vs-print Your better off going in a direction adding more indexes for your tables in mysql and tweaking the statements in the code to process more precisely and accurately. TJ Quote Link to comment Share on other sites More sharing options...
Joel Posted August 4, 2008 Share Posted August 4, 2008 Re: Simple Question There's no point in changing it, it wont make any difference to be honest :/ Quote Link to comment Share on other sites More sharing options...
Spudinski Posted August 4, 2008 Share Posted August 4, 2008 Re: Simple Question print() and echo() aren't exactly the same, replacing them, in some cases(although rare) might result to an error. One is that print() can be used within variable context, echo() can't. $variable = print 'hello world'; $variable; versus $variable = echo 'hello world'; $variable; Quote Link to comment Share on other sites More sharing options...
POG1 Posted August 9, 2008 Share Posted August 9, 2008 Re: Simple Question There is another way.. ?> End the php. I find it easier doing this with editors with the syntax highlighting and you could put a variable like this <?= $varName ?> <?php then start it again Quote Link to comment Share on other sites More sharing options...
Floydian Posted August 9, 2008 Share Posted August 9, 2008 Re: Simple Question pog-one's example is bad programming technique in most cases. An example of when you might wanna put HTML text outside of php tags is when your document header is entirely static. In other words, it always stays the same. Or perhaps your footer might be done this way. Despite any performance differences of different techniques for outputting HTML in a php script, if you look at professionally coded scripts, you really don't see the use of start and end php tags for the sole purpose of outputting one small tid bit of php generated output. For instance, phpBB appears to use some sort of parser that takes html files that are used for templating and swaps out certain things for dynamic content. You might have something like: The phpBB script would swap out BASE_PHPBB_DIRECTORY for whatever that "constant" represented. I know people won't take my word for it, but it is definitely true that use of start and end php tags is, in general, bad programming technique and you should stay away from it. Quote Link to comment Share on other sites More sharing options...
POG1 Posted August 10, 2008 Share Posted August 10, 2008 Re: Simple Question ok, so if i have a website with a header and footer included on every page and i have some dynamic content what would be the point of having it in 1 big echo tag? <?php include('header.php'); ?> blah blah blah</p> <?= $anyVariable ?></p> <?php include('footer.php'); ?> Quote Link to comment Share on other sites More sharing options...
Floydian Posted August 13, 2008 Share Posted August 13, 2008 Re: Simple Question So the header and footer would have the dynamic content, but the body would be static? In that case, the start and end tags would be fine. In contrast, if you had a form with four input elements, and each needed some dynamic content placed in it, I would NOT use start and end tags all through that form. I'd generate the entire form in the context of a heredoc statement. And then, if the rest of the page where static, then by all means, place that content outside of the php tags. It's just like embedded javascript. It's extremely poor programming technique to have javascript embedded all over your document. It should all be condensed into an external js file and attached to the DOM dynamically. PHP can't be attached in the same way as javascript, so you have to have php tags in the HTML somewhere, so it's use should be minimized as much as possible. One or two sets should be all you need. If it starts getting into four, five, six sets of php tags, you really should ask yourself, is there a cleaner way to write this code? 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.