try
echo '<pre>', $text, '</pre>';
if you want to be outputed the way you wrote it
or
echo nl2br($text);
but this way the multiple spaces will be ignored
Main Topics
Browse All TopicsThis code:
$text = <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
END;
echo $text;
print $text;
This appears to me in a single line. Shoudn't it appear in 4 different lines?
This has a broader question which is:
I have an textarea box ... I put the stuff in the Database(mysql) ... it has \n in the middle of the text ... how do I print back the results so that it retains the \n ?
I've been working with PHP for a few years now ... but this still eludes me ... (mainly because I really never needed it ... I always use <br>'s)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You are getting the "here document" (in short heredoc) staff a little wrong. You don't need ";" to end the heredoc statement, but rather to end the variable assignment statement. This little precisation allows you to play tricks like this:
$text = nl2br(<<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
END
);
Business Accounts
Answer for Membership
by: DoppyNLPosted on 2004-02-05 at 00:54:10ID: 10278818
browsers don't look at \n as a new line, but simply as a character they don't have to display.
They only obey to <br /> to make a new line.
Your text example doesn't contain <br /> but \n, thus your browser doesn't show a new line.
either put in <br /> in the initial text or use the function nl2br($text); to convert "\n" to "<br />\n"
regarding your database, \n will also be stored in your database as any other character, so when you retrieve that you can work with \n. If you need to display it in a html page, then you can use nl2br() again to add <br />
If you remember that \n is only treated as a new line character in text-editors and text fields; and <br /> is for new lines in html then it should be fairly simple :)
note: <br /> is the XHTML version of <br> in older versions of HTML.