PDA

View Full Version : Using nl2br in PHP



sky131
April 4th, 2005, 01:59 AM
I had been using nl2br to post a textarea to a MySQL database. When I view the post on a page all is well (ie - the <br> tags have been added).

What I want to do now is echo that info back into a textarea for editing, but have it remove the <br> tags and keep the line breaks. Right now it echoes in the <br> tags and the line breaks so when I repost to the database the lines get doubled. The cure right now is to manually delete all the <br> tags.

Is there a better way to echo the info to the textarea and strip the <br> tags?

Thanks.

Voetsjoeba
April 4th, 2005, 07:09 AM
Yes - what you are doing now is storing the <br/> in MySQL. Don't, output it with <br/>'s but keep it with \n's in the database. That way, you can always nl2br it if you output, but you can also keep it for input fields :)

sky131
April 6th, 2005, 12:42 AM
Yes - what you are doing now is storing the <br/> in MySQL. Don't, output it with <br/>'s but keep it with \n's in the database. That way, you can always nl2br it if you output, but you can also keep it for input fields :)

When I just kept it with \n's in the MySQL it would not echo into the textarea. Is there a way around this?

Voetsjoeba
April 6th, 2005, 06:36 AM
That's weird, that always works for me. What do you mean 'it would not echo' ? Like, nothing at all, or what exactly ?

sky131
April 6th, 2005, 11:15 PM
That's weird, that always works for me. What do you mean 'it would not echo' ? Like, nothing at all, or what exactly ?

It did not work before, but now it does. Thanks for your help!!!

Voetsjoeba
April 7th, 2005, 05:25 AM
Anytime :)