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

PHP Build a Simple PHP Application Listing Inventory Items Mingling PHP and HTML

Oziel Perez
Oziel Perez
61,321 Points

alternative 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.?

Oziel Perez
Oziel Perez
61,321 Points

yes 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)

Logan R
Logan R
22,989 Points

Encapsulate 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

Hi 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
Oziel Perez
61,321 Points

Ahh touche! I never thought generating html through php would decrease performance. Ok then