Skip to content Skip to sidebar Skip to footer

How To Correctly Display Text From Db Which Has HTML Formatting And Text Formatting

I have text in db which looks like this:

blah blah blah

When I get the text out of db and display it, I am able to get the

to make the pa

Solution 1:

You can use :

echo nl2br($db_string);

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

Solution 3:

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.


Post a Comment for "How To Correctly Display Text From Db Which Has HTML Formatting And Text Formatting"