carlg Posted June 20, 2006 Share Posted June 20, 2006 If you're creating a page that is a lot of standard HTML mixed with PHP, which of the 2 methods below is the preferred method and why?Method #1Code the entire page inside PHP start/end tags So you will have a lot of PHP statements that look like thisprint "<TABLE>";Everytime you want to do basic HTML, you need to use a print statement.Method #2Toggle back and forth between HTML and PHP thru the entire document.I just curious which method is preferred. I've seen it done both ways.Thanks for the info Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/ Share on other sites More sharing options...
obsidian Posted June 20, 2006 Share Posted June 20, 2006 [!--quoteo(post=386118:date=Jun 20 2006, 02:47 PM:name=carlg)--][div class=\'quotetop\']QUOTE(carlg @ Jun 20 2006, 02:47 PM) [snapback]386118[/snapback][/div][div class=\'quotemain\'][!--quotec--]If you're creating a page that is a lot of standard HTML mixed with PHP, which of the 2 methods below is the preferred method and why?Method #1Code the entire page inside PHP start/end tags So you will have a lot of PHP statements that look like thisprint "<TABLE>";Everytime you want to do basic HTML, you need to use a print statement.Method #2Toggle back and forth between HTML and PHP thru the entire document.I just curious which method is preferred. I've seen it done both ways.Thanks for the info[/quote]it really depends on the amount of switching back and forth. i can't give you an overarching answer to that one... although, if there is a page with a lot of that, i usually try to make a template so that i don't have to worry about either one. then, you can completely separate the HTML from the PHP, and you can just plug in the PHP values where they need to go. Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-47771 Share on other sites More sharing options...
legohead6 Posted June 20, 2006 Share Posted June 20, 2006 [!--quoteo(post=386118:date=Jun 20 2006, 01:47 PM:name=carlg)--][div class=\'quotetop\']QUOTE(carlg @ Jun 20 2006, 01:47 PM) [snapback]386118[/snapback][/div][div class=\'quotemain\'][!--quotec--]If you're creating a page that is a lot of standard HTML mixed with PHP, which of the 2 methods below is the preferred method and why?Method #1Code the entire page inside PHP start/end tags So you will have a lot of PHP statements that look like thisprint "<TABLE>";Everytime you want to do basic HTML, you need to use a print statement.Method #2Toggle back and forth between HTML and PHP thru the entire document.I just curious which method is preferred. I've seen it done both ways.Thanks for the info[/quote]I use method#1 unless the text isnt dynamic...then i have php at the top then end the php and have text...(cant remember exactly why i had php on that page..but..) Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-47838 Share on other sites More sharing options...
hackerkts Posted June 21, 2006 Share Posted June 21, 2006 I just leave the html alone unless some parts require php coding,so in my scripts there's more than 1 opening and closing php tag.Yeah, I know it's messy :s Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-47886 Share on other sites More sharing options...
.josh Posted June 21, 2006 Share Posted June 21, 2006 a agree with obsidian. it just depends on the script, for me. If the bulk of the page is gonna be html and maybe a few pieces of dynamic info, i'll toggle back and forth. I personally think it gets really messy and confusing popping back and forth between the two. Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-47909 Share on other sites More sharing options...
Guest edwinsweep Posted June 21, 2006 Share Posted June 21, 2006 9 out of 10 times Method NR1.dont really know why.and i used to work with single qoutes, untill i stumbled on a problem when using /n for new lines.then i switched to double qoutes.anybody else have a prefference for single or double qoutes? Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-47981 Share on other sites More sharing options...
carlg Posted June 21, 2006 Author Share Posted June 21, 2006 Thanks for all the input.I kinda also lean towards #1, since I think it gets confusing closing and opening <? ?> tags all of the time.So even if I'm doing a form or something like that and there's 30 lines in the form and 1 of them is dynamic, I still use method #1, so my PHP page just looks like a bunch of statements that look like thisprint "<TABLE>";print "<TR><TD>sdfsdfdsfdsfds";print "<TD>sdf";print "</TABLE>"; Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-47989 Share on other sites More sharing options...
wildteen88 Posted June 21, 2006 Share Posted June 21, 2006 I adopt both methods it depends on what I'm doing.But if I use the first method I dont echo/print line by line I do this instead:echo "<table><tr><td>asjsdjdj></td></tr></table>more html here";Or I use HEREDOC if its large blocks of html.its not work typeing echo or print for each line of html print/echo statements can span muiltple lines so which bother echo/print'ing each line one by one. Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-47991 Share on other sites More sharing options...
obsidian Posted June 21, 2006 Share Posted June 21, 2006 one other thought to consider is the load time of the page. sometimes it's worth it to run a timer and see which method is more optimal for the given page. to me, speed matters, so if i know that one method will load faster for my user than the other, i'd prefer to use that method. Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-47993 Share on other sites More sharing options...
DaveLinger Posted June 21, 2006 Share Posted June 21, 2006 [!--quoteo(post=386350:date=Jun 21 2006, 07:39 AM:name=carlg)--][div class=\'quotetop\']QUOTE(carlg @ Jun 21 2006, 07:39 AM) [snapback]386350[/snapback][/div][div class=\'quotemain\'][!--quotec--]Thanks for all the input.I kinda also lean towards #1, since I think it gets confusing closing and opening <? ?> tags all of the time.So even if I'm doing a form or something like that and there's 30 lines in the form and 1 of them is dynamic, I still use method #1, so my PHP page just looks like a bunch of statements that look like thisprint "<TABLE>";print "<TR><TD>sdfsdfdsfdsfds";print "<TD>sdf";print "</TABLE>";[/quote]you dont need "print" on every line.print "<TABLE><TR><TD>sdfsddfsdfds</TD><TD>sdf</TD></TABLE>"; Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-48068 Share on other sites More sharing options...
complex05 Posted June 21, 2006 Share Posted June 21, 2006 I always use PHP no matter what... if you find that most of the site will be in HTML, then do one of theseecho<<<endhtmlBULK OF HTML CODING HEREendhtml;that way if you need to print some variables in there, you don't need to toggle. And you don't have to worry about using quotes or anything, because that structure allows anything.Hope this helps!Barry Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-48086 Share on other sites More sharing options...
cwncool Posted June 21, 2006 Share Posted June 21, 2006 Method two normally. Ocasionally #1, but not often. Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-48087 Share on other sites More sharing options...
DaveLinger Posted June 21, 2006 Share Posted June 21, 2006 [!--quoteo(post=386448:date=Jun 21 2006, 11:29 AM:name=complex05)--][div class=\'quotetop\']QUOTE(complex05 @ Jun 21 2006, 11:29 AM) [snapback]386448[/snapback][/div][div class=\'quotemain\'][!--quotec--]I always use PHP no matter what... if you find that most of the site will be in HTML, then do one of theseecho<<<endhtmlBULK OF HTML CODING HEREendhtml;that way if you need to print some variables in there, you don't need to toggle. And you don't have to worry about using quotes or anything, because that structure allows anything.Hope this helps!Barry[/quote]anything? what if I need to print "endhtml;" in my html? [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-48091 Share on other sites More sharing options...
Buyocat Posted June 21, 2006 Share Posted June 21, 2006 I strongly suggest using Smarty for this problem, [a href=\"http://smarty.php.net/\" target=\"_blank\"]http://smarty.php.net/[/a], it is really easy to use and install. The only trick to installion is that your permissions are right. As for use it happily sidesteps the problem you've outlined above by letting you put all of your html in separate template files. This means that you can concentrate on the the business logic in classes that are doing work moving objects/data around and leave the visual logic to the template. As an added bonus you can cache your compiled templates, which means that you won't have to remake the page every time someone wants to load it; this translates into faster load times. Finally, Smarty has a ton of plug-ins, and it is as easy as creating a function to add a custom one, that let you do things like strip slashes, format date, etc. I strongly recommend something like Smarty if you want to keep your code separated by function. Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-48094 Share on other sites More sharing options...
lpxxfaintxx Posted June 21, 2006 Share Posted June 21, 2006 I tend to useecho <<<__HTML_END__HTML_END;a lot... I don't know why, but I feel more comfortable. Quote Link to comment https://forums.phpfreaks.com/topic/12481-your-style-of-php-programming/#findComment-48141 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.