Page 1 of 1

carriage return 'retrieval' from mySQL database

Posted: Sun Feb 15, 2004 11:19 pm
by Smeagol
Hi guys,

I have a quick question. I have a form which, when submitted, enters the data into a field in a mySQL database of type text.

When I retrieve the information/text from the database, I need to be able to detect carriage returns and convert them to display a properly formatted piece of text in HTML with either <br> or <p> for every carriage return.

How would I do this?

Thanks.

Posted: Sun Feb 15, 2004 11:26 pm
by Smeagol
Okay,

I just found out the nl2br() function... that's cool, but what about paragraphs? I hate <br> tags :) heheh

Posted: Thu Feb 01, 2007 10:49 am
by Ostrya
Try using str_replace to insert a paragraph tag. It works for me.

Code: Select all

$htmlText = str_replace("\n", "<p>", "$yourQueryTextField");