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 trialNick Woodland
13,870 PointsWhy is the <li> tag kept outside the php tags?
It seems odd having that lone closing curly brace inside it's own php tag.
2 Answers
Michalis Efstathiou
11,180 Points<li>
is an html tag, if you keep it within php code php will not know what it is and will not execute
what you are essentially doing is telling the php parser to stop parsing after the opening curly brace, and start again right before the closing curly brace. it doesnt bother with the stuff in the middle and sends it to the browser as is, ie. html code
an alternative you can do is echo the html as string text, so that php will send it as text to the browser, and then the browser can parse it as html. eg.
echo "<ul>";
echo "<li>list item 1</li>";
echo "<li>list item 2</li>";
Michael Jurgensen
8,341 PointsYes it seems odd but you could write it this way:
<?php foreach($social_icons as $icon) { echo "<li> ..... </li>"; } ?>
Nick Woodland
13,870 PointsNick Woodland
13,870 PointsThanks for that, I was incorrectly assuming that the php interpreter would understand the html tags.
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsThey say not to mess PHP with HTML code and keep it separately because if e.g something goes wrong or whatever , if i remember well, its still good or something : p if im correct
Konrad Pilch
2,435 PointsKonrad Pilch
2,435 PointsOh well, its over 9 months xd, how are you getting on? :D did you made a social website or something ? :D