Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Derrick Lee
7,743 PointsQuestion regarding <?php ?>
Hey guys, I have been following the php videos today and I wonder to myself. Why not add the <?php ?> tags at the start and end of the document, and continue to code HTML and PHP tags inside instead of having many <?php ?> tags in the document to encode each php command?
I understand that if we do </php at the start of the document and ?> at the end of the document, our HTML syntax will need to be changed slightly too.
To better understand my question, here's an example.
The two chunks of examples are separated by the dashes. Please note that I was unable to enter this code in this post and therefore had to use an image. I also realized that i forgot the double quotes at the second example of the conditional statement. Apologies for that.
4 Answers
Chad Shores
Courses Plus Student 8,868 PointsEither way works great. I prefer the bottom style, but use whichever style the task at hand calls for.
Derrick Lee
7,743 PointsAh got it! Thanks!
Randy Hoyt
Treehouse Guest TeacherIt can get pretty tricky to edit code written in that first style, especially when working with more PHP variables and with more complicated HTML. It's a really good practice to keep the HTML and PHP code as separate as possible. I'll be talking about that more in the next set of videos on Refactoring, which will be released very soon.
Derrick Lee
7,743 PointsGreat! I'll be waiting! Thanks!
