RCB Posted February 15, 2009 Share Posted February 15, 2009 hey guys am new to the site and to the world of php i have a pretty simple question and was wondering if someone could help... my question is which way is better input/output html in a php file? and is one way quicker then the other or does it if make a difference... examples: (please keep in mind that this would be based on a much larger code then just the example) 1 <?php if blah blah = blah blah { echo <<<HTML a bunch of blah blah html more html and more blah HTML; }else { echo <<<HTML else blah html HTML; } ?> 2: <html> blah blah code html <?php if blah blah = blah blah { ?> blah blah html code here <?php }else { ?> else blah blah code here <?php } ?> </html> thx for your help guys RCB Quote Link to comment https://forums.phpfreaks.com/topic/145302-whats-the-standard-for-html-in-php/ Share on other sites More sharing options...
bothwell Posted February 15, 2009 Share Posted February 15, 2009 I much prefer the second method. When I first started out, I echoed everything and as a result I'm still maintaining a really horrible nightmare app that's got echos everywhere and it's incredibly hard to follow. If anything now I try to avoid putting my HTML into php logic files in the first place - I'll just use include('somehtml.php'); instead of having it all in the one file. Makes things so much easier to follow. Quote Link to comment https://forums.phpfreaks.com/topic/145302-whats-the-standard-for-html-in-php/#findComment-762780 Share on other sites More sharing options...
.josh Posted February 15, 2009 Share Posted February 15, 2009 It depends on the circumstance. But overall, the "standard" is to separate code from content as much as possible. Like for instance, in your examples, you should be assigning the text to a string and passing it to a page meant only for displaying results, not mixing logic and output. Read up on MVC (model view control). Quote Link to comment https://forums.phpfreaks.com/topic/145302-whats-the-standard-for-html-in-php/#findComment-762782 Share on other sites More sharing options...
allworknoplay Posted February 15, 2009 Share Posted February 15, 2009 It's really preference dude....whatever you feel comfortable doing it in...there's various ways to output HTML via PHP..... My way is to try as much as possible not to put HTML within PHP code... Quote Link to comment https://forums.phpfreaks.com/topic/145302-whats-the-standard-for-html-in-php/#findComment-762783 Share on other sites More sharing options...
RCB Posted February 17, 2009 Author Share Posted February 17, 2009 thanks for the replies... im not really sure how to separate the logic and output or how to assign text to a string... im still an infant to php would someome be able to post some examples thanks again Quote Link to comment https://forums.phpfreaks.com/topic/145302-whats-the-standard-for-html-in-php/#findComment-764126 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.