Forum Moderators: coopster

Message Too Old, No Replies

nl2br, use for some not for all

How to check $text format and then use nl2br($text)

         

Jaunty Edward

5:38 am on Aug 13, 2005 (gmt 0)

10+ Year Member



Hi,

I have a mySQL DB with a table that has a data type text. There are 1000's of entries some of them does not need php based nl2br() and some of them requeires it. If I use

nl2br($text)

for some entries it is showing properly as

line one
line two
line three

while for some it shows

line one line two line three

Please tell me how can I fix this problem. I will be happy if I can fix the entries in the DB it self however if there is a way I can show it properly in php it will be fine too.

Thanks
Bye

roldar

5:43 am on Aug 13, 2005 (gmt 0)

10+ Year Member



I don't know what type of text you're outputting, but if you'd like to enclose paragraphs in <p>'s give this a try:

str_replace("\r\n", "<br />", str_replace("\r\n\r\n", "</p><p>", $text));

(of course, you'll have to hard-code the initial <p> and the ending </p>)