php - Displaying a Paragraph with line breaks

257

I have a situation where users can enter a question and this is written into a mysql table.

I then show this text in an admin panel for reivew and reply.

I can see the text in the admin panel has the same new lines (chrome developer) but it shows as one block of text (no new lines)...

I'm currently using to show this text... I've tried a but it still hows without line breaks.

How should I go about displaying this text with the new lines it contains? Is there a HTML tag to do this or do I need to use PHP and sub \n for br tag?

example below:

 <span class="description">txthere


 txthere


 txthere


 txthere


 txthere.</span>
325

Answer

Solution:

On display you can use CSS to style the HTML with the original line breaks, trywhite-space:

white-space: pre-line;
467

Answer

Solution:

if it is textarea or console basically it puts a line break using/n which is not recognized by the browser as line break, you need to convert/n to<br/> to tell the browser that this is a line break, use this php's function

nl2br();

more information here: http://in.php.net/nl2br

this will convert all your/n tag to<br/> tag so that browser process it as line breaks

People are also looking for solutions to the problem: php - Exactly how does the defaultValue work in Symfony 2.0 NodeDefinition?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.