Ge64 Posted May 17, 2008 Share Posted May 17, 2008 I've used PHP for a while and every time I do this differently, but I don't think I'm happy with any of the methods. In the end, a PHP file gets evaluated and becomes HTML, but most of the time you need to put in HTML elements like <table> and <div> in order to form your basic layout, but you add in PHP code in between and all over the place. So, do you start out with a PHP file and add in HTML where you need it? If so, how do you add in the HTML, do you echo it or do you make holes in the PHP? OR do you start with a proper HTML page and put in PHP parts wherever you need PHP, meaning you'll have <?php echo ... ?> all over the place as if there were HTML tags. If you are making a table out of what you get from a MySQL database, do you just have a script somewhere that processes the data, then a HTML table with <?php echo $avalue; ?> inside it, or do you make a php script with echo "<tr><td>" . $avalue . "</tr></td>"; in it? What is the best way to do it, what is the best way to keep it looking neat and organised and what is the best way performance-wise? Link to comment https://forums.phpfreaks.com/topic/106071-html-inside-php-or-php-inside-html-what-to-do/ Share on other sites More sharing options...
DarkWater Posted May 17, 2008 Share Posted May 17, 2008 Use Smarty or use the HTML inside of PHP method. Link to comment https://forums.phpfreaks.com/topic/106071-html-inside-php-or-php-inside-html-what-to-do/#findComment-543630 Share on other sites More sharing options...
GingerRobot Posted May 17, 2008 Share Posted May 17, 2008 It's almost entirely user preference, though it does depend on the situation. For situations with lots of HTML and little PHP, i close the PHP tag and only echo variables where i need them. For something with lots of variables, i'd echo everything. As i say though, this is personal preference. There are of course other altenatives, like the heredoc syntax. Link to comment https://forums.phpfreaks.com/topic/106071-html-inside-php-or-php-inside-html-what-to-do/#findComment-543644 Share on other sites More sharing options...
phpzone Posted May 17, 2008 Share Posted May 17, 2008 I prefer either the HEREDOC syntax, usually if I know the script are only for my editing, if its a commercial client project and the client needs access to templates I use Smarty Templates. Heredoc syntax is great, and underused by many, you just need to be careful with the closing Heredoc marker, sometime editors add space after the marker and it causes no end of havoc $message = 'Goodbye'; print <<<_SIGNOFF <h1>{$message}</h1> _SIGNOFF: Link to comment https://forums.phpfreaks.com/topic/106071-html-inside-php-or-php-inside-html-what-to-do/#findComment-543656 Share on other sites More sharing options...
Ge64 Posted May 18, 2008 Author Share Posted May 18, 2008 Wow those are some great ideas! I'm now using Smarty but I'm sure the heredoc syntax will come in handy some time, I'd never heard of these. Link to comment https://forums.phpfreaks.com/topic/106071-html-inside-php-or-php-inside-html-what-to-do/#findComment-543983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.