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!
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
David Choi8,536 Points
Formatting PHP Output
In the PHP course, the teacher, Alena Holligan, always uses the escape "\n" when making an output to the screen. So, for example, in the video for Foreach-Loops, she writes the code:
echo $key . ' = ' . $item['title'] . "<br />\n";
However, after experimenting, I found that the formatting on the screen is exactly the same with or without the "\n". Is there a special reason why she uses the escape, or is it just a personal choice?
Jason AnelloCourses Plus Student 94,610 Points
Hi davidchoi2 ,
<br> tag is what produces the line breaks when you view the rendered page in your browser.
\n is for adding line breaks to the source html file that gets sent to the browser.
If you right click your webpage, you should have an option to "View Page Source". This is going to show you all the html that the php script produced and sent to the browser.
Try viewing the page source once with the
\n there and then try again without the
\n. You should see a difference.
With the line return in the code, you should see all the key/title pairs on their own line. Without the line return, they should all be on one long line.