0

I have text in db which looks like this:

<p>
blah blah

blah
</p>

When I get the text out of db and display it, I am able to get the <p></p> to make the paragraph space, but the paragraph between the lines of blah does not show up.

When I try to make it work together, I end up with new lines after the natural new line from pressing the enter, and new line from <p> so I end up with way too much space between paragraphs.

Is there a way to make sure both ways of formatting work together nicely?

1
  • 2
    You have to replace newlines (\n) with <br> tags before displaying Commented Jan 31, 2012 at 19:20

3 Answers 3

4

You can use :

echo nl2br($db_string);
Sign up to request clarification or add additional context in comments.

1 Comment

While this is technically correct and may produce the desired result, it appears the OP is simply misusing the paragraph tag.
2

I'd say the correct way to go about this is fixing the HTML. This doesn't seem like a PHP issue. You say you want to display space between the first line blah blah and the second line blah. I would rewrite it to be:

<p>
    blah blah
</p>
<p>
    blah
</p>

Comments

1

You can apply this css rule

p {
    white-space: pre;
}

If you do it this way, then you won't need to do any transformation of the string itself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.