carriage return 'retrieval' from mySQL database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Smeagol
Forum Newbie
Posts: 14
Joined: Tue Jan 20, 2004 11:51 pm

carriage return 'retrieval' from mySQL database

Post 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.
User avatar
Smeagol
Forum Newbie
Posts: 14
Joined: Tue Jan 20, 2004 11:51 pm

Post by Smeagol »

Okay,

I just found out the nl2br() function... that's cool, but what about paragraphs? I hate <br> tags :) heheh
Ostrya
Forum Newbie
Posts: 1
Joined: Wed Jan 31, 2007 9:52 pm

Post by Ostrya »

Try using str_replace to insert a paragraph tag. It works for me.

Code: Select all

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