Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Trevor Wood
Trevor Wood
17,828 Points

A quick question about PHP

In a text of code like this, the " marks and the ' confuse me a little. To be certain let me see if I got this right.

The first ' is paired with the last ' while the two in the middle are paired together? Or is it opposite? If not, how can the browser distinguish the difference? Because they're inside the " marks does it allow the browser to comprehend?

 echo '<a href="shirt.php?id=' . $product_id . '">';

Any help on this is much appreciated.

1 Answer

I believe the first two will pair together, turning this block of code into a string

'<a href="shirt.php?id='

Then you concatenate the variable, and to that variable you concatenate the next part of your code between single '

'">'

So it's not like html where the tags are nested. The first is closed with the second, the third is closed by the fourth. The " inbetween is treated like a part of the string I suppose, and not considered an opening mark by php.

Trevor Wood
Trevor Wood
17,828 Points

ah, okay I see. I guess that would explain the need for the periods for $product_id.

Thanks Jean +1