Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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...

Frontend Web Developer

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

Frontend Web Developer


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.