Page 1 of 1

Textarea to MySQL with linebreaks

Posted: Mon Aug 28, 2006 8:54 am
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?

Posted: Mon Aug 28, 2006 9:02 am
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.

Posted: Mon Aug 28, 2006 9:13 am
by Case-
What is wrong with my question!?

But thanks for the info, I'll try it.

Posted: Mon Aug 28, 2006 9:15 am
by darodesign
You had have send us your Script, this would be easier :D

Posted: Mon Aug 28, 2006 3:43 pm
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."

Posted: Mon Aug 28, 2006 3:51 pm
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?

Posted: Mon Aug 28, 2006 4:34 pm
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?

Posted: Tue Aug 29, 2006 7:41 am
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 []?

Posted: Tue Aug 29, 2006 8:50 am
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

Posted: Tue Aug 29, 2006 9:33 am
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.