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

working with get variable

I'm just curious why on the videos introducing GET, the php is written on twice instead of just once. why does the first line have } ?> at the end? <?php if ($_GET["status"] == "thanks") { ?> <p>Thanks for the email. I will be in touch shortly.</p> <?php } ?>

1 Answer

It's because inside of that if block, we are not doing anything else with PHP. We are just simply spitting out HTML. To spit out HTML in PHP, we have to use echo, and wrap in in quotes, and all of that can get quite messy. The PHP server doesn't really care that one if statement is broken up into two PHP blocks, because the PHP is all processed together, before it get's sent to the browser. PHP doesn't know what is inside that block, but it still recognizes it just fine as a block.

As long as the PHP tags are open and closed correctly, and the statements are open and closed correctly, it doesn't matter how many php tags are used.