Textarea to MySQL with linebreaks

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
Case-
Forum Newbie
Posts: 22
Joined: Fri Aug 04, 2006 5:52 am
Location: Finland

Textarea to MySQL with linebreaks

Post by Case- »

How can I get teaxareas text to MySQL DB with linebreaks,
im building an news add form, but the line breaks wont work.
Should I write pure html to the box or what?
User avatar
darodesign
Forum Newbie
Posts: 19
Joined: Mon Aug 28, 2006 8:58 am
Location: Berlin
Contact:

Post by darodesign »

Please next time do a better question!

I think you need is nl2br, which converts Unix breaks \n to HTML breaks <br />.

I hope this is what you needed.
User avatar
Case-
Forum Newbie
Posts: 22
Joined: Fri Aug 04, 2006 5:52 am
Location: Finland

Post by Case- »

What is wrong with my question!?

But thanks for the info, I'll try it.
User avatar
darodesign
Forum Newbie
Posts: 19
Joined: Mon Aug 28, 2006 8:58 am
Location: Berlin
Contact:

Post by darodesign »

You had have send us your Script, this would be easier :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Don't do an nl2br() on the way into the database, only on in-page display. Why? Well you will eat up some storage space using it and what if someone wants to edit the post? Now you have to str_replace() it back to "normal."
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

Are there newlines in the text area when the user hits submit? If so, then they should go into the database.

When you say they won't work, exactly how don't they work?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

How do you plan to handle new lines on user input?If you do away with them, then you end up with one long string. Is that what you want?
User avatar
Case-
Forum Newbie
Posts: 22
Joined: Fri Aug 04, 2006 5:52 am
Location: Finland

Post by Case- »

The nl2br() helped me, I use it only when im reading the text from the Database so it wont mess it up.

The next problem is, how can I add html codes in the textbox like links and images,
or make it work like this reply form wher I can add links with the []?
User avatar
darodesign
Forum Newbie
Posts: 19
Joined: Mon Aug 28, 2006 8:58 am
Location: Berlin
Contact:

Post by darodesign »

If I understand your question right, you meen JavaScript, like here in this Board if you click the URL Buttons it inserts Code to the Textbox.

Else maybe you ment this Functions:
http://php.net/htmlspecialchars
http://php.net/htmlentity
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you're talking of the tags we have here, e.g. [url], Google for "bbcode parser" .. there are quite literally lots of ones available, including one from PEAR.
Post Reply