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 trial

PHP PHP Basics (Retired) PHP Datatypes Strings

why i m not getting line breaks after first string ?

<?php $user_name = "ABC \n"; $user_pro = "Frontend Web Developer"; echo $user_name; echo $user_pro; ?>

4 Answers

If the output display is a web page you would need to wrap the output in PRE tags to enable regular line breaks. For example...

<pre>
ABC\n
Frontend Web Developer
</pre>

Otherwise it may be easier to use a BR tag instead of a newline indicator. For example...

ABC<br>
Frontend Web Developer

Cheers!

thanx but what pre is ?

I'm not sure what you mean. Can you rephrase "...what is ?"

pre ?

Ah right! PRE is an HTML element for containing pre-formatted text. This means text inside a PRE element will retain spaces, tabs, and line breaks. This is very different than most HTML elements which ignore things like more than one sequential space.

The Mozilla Developer Network has more details on the PRE element if you are interested. There is also a good explanation of the PRE element at SitePoint.

thanx