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 trialRobert Villareal
14,566 Pointsconcatenation
Hello,
I'm curious on why this:
echo '<img src="' . $product["img"] . '" alt="' . $product["name"] . '">';
works, while this:
echo '<img src=" . $product['img'] . " alt=" . $product['name'] . ">';
does not. Everything is paired up nicely on the code that does not work. Why do we need the extra single quotes on the code that works?
Robert Villareal
14,566 PointsOops!! Sorry about that Ben. Edited my original post.
5 Answers
Andrew Shook
31,709 Pointsecho '<img src="' . $product["img"] . ' " alt=" ' . $product["name"] . ' ">';
// output: <img scr="url/to/img.jpg" alt="alt text">
echo '<img src=" . $product['img'] . " alt=" . $product['name'] . ">';
// output: <img scr=url/to/img.jpg alt=alt text>
The challenge isn't passing with the second one because it is generating improper html. HTML attributes values have to be surrounded by quotes.
Agapito Cruz
21,486 PointsAre you sure you entered the code snippets correctly? On my screen, both code snippets have 6 paired up single-quote characters. I don't seen an 'extra' single quote on either.
Robert Villareal
14,566 PointsJust edited my original post. Thanks for checking it out.
Agapito Cruz
21,486 PointsYou need the closing single quote on the first part of your string *'<img src=" *, The ending doublequote charaacter does not close it.
Robert Villareal
14,566 PointsThank you all for the quick response. :D
Andrew Shook
31,709 PointsRobert, did you figure the problem out?
Robert Villareal
14,566 PointsHi Andrew,
I did. Thanks for following up on me.
Ben Griffith
5,808 PointsBen Griffith
5,808 PointsApologies if I'm going mad, but both lines of code appear to be identical!