Hey all,
What is the most efficient (quickest) way of writing the HTML output of a PHP script?
embed the php within the HTML?
use echo "<table></table>"
or use print?
I've seen in done all three ways...
Embed it. Use as few PHP as possible and you'll end up fastest. If time is mission critical (I speak parsing of complete pages here) you should spend weeks on code efficiency. Otherwise... just embed it 🙂
Dominique
yep, that would be about right. The but, and you knew it was coming, is that speed isn't always the issue (contrary to popular belief), sure people will piss of after about 8-10secs of waiting for some silly 'spash page' to load but the easier answer is sensible design. If your not doing anything ridiculusly out of the ordinary the best way to go is Templates. You'll never look back!
Good luck
Nick
Oh yeah I forgot that one. Templates are great, relatively fast - depending on codedesign of the interpreter - and procude redable and reusable code. What helps as well is using layers. I find database layers and a html layer quite useful. Both can be found either here or at zend.com.
Greets,
That's not allways true.
http://www.phpbuilder.com/forum/read.php3?num=2&id=147556&loc=0&thread=147556
In some cases it's faster to print/echo some html than to stop and restart the PHP block. (echo is faster than print btw)
So my advice is: use a method that keeps your code readable and clean.
Don't try to optimize your code before there is a need to do so. Your primary objective is to get the code working and stable. When that is done you can worry about performance.