Page 1 of 1

retrieving content from textarea

Posted: Sun Jul 16, 2006 9:15 pm
by djuritz
I have a form with one textarea for comments.
The problem is when there are line breaks (by pressing [enter]).
When I build the INSERT query for MySQL, the source code is semething like this:

INSERT INTO [table] (comments) VALUES ('This is my comment
with holy breaks')

Although It works, when this data is shown on the page, the source code is this:
<td>This is my comment
with holy breaks</td>

The point is that I need to display this content using overlib (javascript library) and It doesn't like these breaks, and it doesn't work.
The string should be like this: This is my comment<br />with holy breaks.

I've tried using PHP's function nl2br(), but I get the same string with boths elements: page break and <br />:
"This is my comment<br />
with holy breaks."

And that is even worst!

I'm also using smarty template, and it has a internal function nl2br too, but I get the same result.

What on earth is the problem?!
Thanks!

Posted: Sun Jul 16, 2006 9:21 pm
by feyd
str_replace() newlines with nothing or <br /> depending on if you remove the nl2br() call or not.

Posted: Sun Jul 16, 2006 10:21 pm
by djuritz
feyd wrote:str_replace() newlines with nothing or <br /> depending on if you remove the nl2br() call or not.
It worked out by using str_replace("\r\n", " ", $txt);

Thanks a lot!
Diego.-