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 trialOziel Perez
61,321 Pointsalternative way to mingling html
Wouldn't it be easier to just echo the p tag and concatenate the variable rather than creating a whole bunch of php tags? It seems to work for me when I do it this way, but I'm wondering if there's any difference in what I typed above compared to this:
If (something == true) { <p>>My favorite flavor is <?php echo $flavor ?><</p> }
....or is it just a matter of preference.?
Logan R
22,989 PointsEncapsulate your code with three . So at the top of the if, add three
and at the bottom of the }, add three `.
That probably doesn't make a lot of sense but if you look on the right, under the header "Tips for asking questions", click and watch the video :)
1 Answer
Muhammad Mohsen
Courses Plus Student 10,843 PointsHi Oziel,
The important thing to know is when you echo any HTML tag within PHP it will be executed on your server first, then the server will send it to the browser.
Simply, let everyone do his job.
- Web Server: Run and execute PHP code and sent it to the browser.
- Browser: Show HTML, JS, CSS, etc.
no need to overload your server with executing HTML code.
Oziel Perez
61,321 PointsAhh touche! I never thought generating html through php would decrease performance. Ok then
Oziel Perez
61,321 PointsOziel Perez
61,321 Pointsyes i am aware of the random < > signs at the start and end of the command inside the if statment (the p element keeps disappearing when i type my question)