retrieving content from textarea

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
djuritz
Forum Newbie
Posts: 2
Joined: Fri May 12, 2006 12:51 pm

retrieving content from textarea

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

str_replace() newlines with nothing or <br /> depending on if you remove the nl2br() call or not.
djuritz
Forum Newbie
Posts: 2
Joined: Fri May 12, 2006 12:51 pm

Post 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.-
Post Reply