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 trialLinda Wohlgemuth
2,510 PointsWhy do I need both "<br />" AND "\n" ?
Alena used two methods for a new line in her example: do {echo $year . "<br />\n";} while (++$year <= $currentYear)
I tried out some stuff and it seems that my browser needs the HTML <br /> to create a new line and the Console needs the "\n". But I don't get why, or why the other one is ignored and not shown.
And when I'm using php for a website - is it enough to use "<br />" or do I always need both?
1 Answer
Steven Parker
231,248 PointsNewlines don't affect the browser rendering of a page, but they can improve the readability of the source. So if that's not of any value you can omit them there. But it would be worthwhile to use both if a human (perhaps even yourself) will need to inspect the code.
On the other hand, HTML tags are not processed by the console, so for console output you would only use newlines and not <br> tags.
Linda Wohlgemuth
2,510 PointsLinda Wohlgemuth
2,510 PointsThanks for your answer. Where would I see this code then? Since all my browser gives me is the html <br />. Can I look in the "translating" of a server?
Sorry for asking this noobie-stuff! ^^
Steven Parker
231,248 PointsSteven Parker
231,248 PointsMost browsers have some sort of "show source" or "inspect" capability, plus you can generally "save page as" and then view the file it makes with a text editor.
Linda Wohlgemuth
2,510 PointsLinda Wohlgemuth
2,510 PointsYes, but the Console of a php-based Website is empty in my "inspector" - I thought it was because the server only gives the html.
So I can't think of an situation where I can see both - the console and the browser. But maybe I will in the future. Anyway thank you for your help.
Linda Wohlgemuth
2,510 PointsLinda Wohlgemuth
2,510 PointsAAAAAAAnd here we go. It's the case. Alena explains the "inspector-thing" in one of the next videos (Todo App at 02:00)