473,320 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to handle line breaks when storing textarea entry in a database?

I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags
in HTML. How can I do that. So far, although it occurs naturally when
I save the contents to a file, it doesn't break up the paragraphs
properly when I save it to my database.

Thanks!

Jonathan
http://thewebdevelopment.com
Jul 20 '05 #1
6 62878
"Jonathan" wrote:
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally when I save the contents to a file, it doesn’t break up the
paragraphs
properly when I save it to my database.

Thanks!

Jonathan
http://thewebdevelopment.com


Jonathan, textarea uses cr\lf to break lines. That is how it would
be saved into db, if your program does no extra translations. Upon
display on html page, cr\lf could then be replaced by html break
tags.

I don’t know of paragraph breaks. I believe that is simply double
cr\lf’s.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-handle...ict131179.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438213
Jul 20 '05 #2

"Jonathan" <th***************@yahoo.com> wrote in message
news:67**************************@posting.google.c om...
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags
in HTML. How can I do that. So far, although it occurs naturally when
I save the contents to a file, it doesn't break up the paragraphs
properly when I save it to my database.

You need to replace your \r\n with <p />
and your \n with <br />

php code sample (handles dos and *nix text):

$string = ereg_replace("(\r\n\r\n|\n\n|\r\r)", "<p />", $_POST['testtext']);

^^^^^^^^^^^^^

Text from query

$string = stripcslashes(ereg_replace("(\r\n|\n|\r)", "<br />", $string));

print $string;
Jul 20 '05 #3
"Jonathan" wrote:
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally when I save the contents to a file, it doesn’t break up the
paragraphs
properly when I save it to my database.

Thanks!

Jonathan
http://thewebdevelopment.com


Jonathan, textarea uses cr\lf to break lines. That is how it would
be saved into db, if your program does no extra translations. Upon
display on html page, cr\lf could then be replaced by html break
tags.

I don’t know of paragraph breaks. I believe that is simply double
cr\lf’s.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-handle...ict131179.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438213
Jul 20 '05 #4

"Jonathan" <th***************@yahoo.com> wrote in message
news:67**************************@posting.google.c om...
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags
in HTML. How can I do that. So far, although it occurs naturally when
I save the contents to a file, it doesn't break up the paragraphs
properly when I save it to my database.

You need to replace your \r\n with <p />
and your \n with <br />

php code sample (handles dos and *nix text):

$string = ereg_replace("(\r\n\r\n|\n\n|\r\r)", "<p />", $_POST['testtext']);

^^^^^^^^^^^^^

Text from query

$string = stripcslashes(ereg_replace("(\r\n|\n|\r)", "<br />", $string));

print $string;
Jul 20 '05 #5
steve wrote:
"Jonathan" wrote:
> I want to save textarea contents to a mysql database with the
> paragraph breaks intact without having to type paragraph or break

tags
> in HTML. How can I do that. So far, although it occurs naturally

when
> I save the contents to a file, it doesn’t break up the
> paragraphs
> properly when I save it to my database.
>
> Thanks!
>
> Jonathan
> http://thewebdevelopment.com


Jonathan, textarea uses cr\lf to break lines. That is how it would
be saved into db, if your program does no extra translations. Upon
display on html page, cr\lf could then be replaced by html break
tags.

I don’t know of paragraph breaks. I believe that is simply double
cr\lf’s.

I would like to suggest a small correction:

A 'paragraph break' is actually CR/LF. A textarea will break lines using
wordwrap. (To some people a paragraph break is known as a 'hard break':
its hard-coded, whereas a wordwrap is a 'soft break': software
calculates it.) A wordwrap doesn't actually use any symbol wthin the
stored text, since the position of the line breaks will alter depending
on the media in which the text is displayed.

HTML also uses wordwrap, but it ignores CR/LF. In its place you can use
either a <BR> for linebreak or <p> for paragraphs. If you have a block
of text which uses CR/LFs that you wish to display in HTML, then you'll
need to substitute <br> for each of the CR/LFs. (in PHP there is a
function nl2br() that does this.)

History: CR/LF goes back to the days of early printers where the codes
replicated the actions of a typewriter. CR (carriage return) returned
the carriage to the start of a new line. LF (line feed) advanced to the
next line. The lever at the left end of a typewriter combined moving
the carriage and advancing the line. Typists used to apply a CR/LF at
the end of every line and an extra CR/LF between paragraphs. As electric
typewriters came into use they would automatically apply the CR/LF when
the end of the line was reached.

Now with wordprocessing and wordwrap, the CR/LF at the end of each line
is no longer neccessary.

Any corrections/improvements to this explanation would be greatfully
received.

Mike
Jul 20 '05 #6
steve wrote:
"Jonathan" wrote:
> I want to save textarea contents to a mysql database with the
> paragraph breaks intact without having to type paragraph or break

tags
> in HTML. How can I do that. So far, although it occurs naturally

when
> I save the contents to a file, it doesn’t break up the
> paragraphs
> properly when I save it to my database.
>
> Thanks!
>
> Jonathan
> http://thewebdevelopment.com


Jonathan, textarea uses cr\lf to break lines. That is how it would
be saved into db, if your program does no extra translations. Upon
display on html page, cr\lf could then be replaced by html break
tags.

I don’t know of paragraph breaks. I believe that is simply double
cr\lf’s.

I would like to suggest a small correction:

A 'paragraph break' is actually CR/LF. A textarea will break lines using
wordwrap. (To some people a paragraph break is known as a 'hard break':
its hard-coded, whereas a wordwrap is a 'soft break': software
calculates it.) A wordwrap doesn't actually use any symbol wthin the
stored text, since the position of the line breaks will alter depending
on the media in which the text is displayed.

HTML also uses wordwrap, but it ignores CR/LF. In its place you can use
either a <BR> for linebreak or <p> for paragraphs. If you have a block
of text which uses CR/LFs that you wish to display in HTML, then you'll
need to substitute <br> for each of the CR/LFs. (in PHP there is a
function nl2br() that does this.)

History: CR/LF goes back to the days of early printers where the codes
replicated the actions of a typewriter. CR (carriage return) returned
the carriage to the start of a new line. LF (line feed) advanced to the
next line. The lever at the left end of a typewriter combined moving
the carriage and advancing the line. Typists used to apply a CR/LF at
the end of every line and an extra CR/LF between paragraphs. As electric
typewriters came into use they would automatically apply the CR/LF when
the end of the line was reached.

Now with wordprocessing and wordwrap, the CR/LF at the end of each line
is no longer neccessary.

Any corrections/improvements to this explanation would be greatfully
received.

Mike
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Christopher Glaeser | last post by:
Consider the code: $arrText = file ("http://www.site.com/page.htm"); for ($i=0; $i<count($arrText); i++) { echo("$arrText\n"); } (I did not test the snippet for errors) The line breaks...
0
by: Jonathan | last post by:
I want to save textarea contents to a mysql database with the paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally...
4
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary...
0
by: Peter Rilling | last post by:
Although an ADODB question, I am using C#, so here I go. I am trying to use the ADODB Stream object to extract content from a body part of an MHTML formatted document. I can save the raw...
5
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the...
8
by: Juan Puebla | last post by:
Hi, I have an sql database with some text (nvarchar) fields. The problem is that if I get those fields with a datareader (dr.getstring(0)) an then I save text in a txt file I loose all the line...
14
by: ghostwalker | last post by:
Hi I have an HTML form with a textarea on it. When submitted (using 'get' not 'post') this forms action php file simply does this to retrieve the values: $message = $_GET; Now it all works...
1
by: Arielle | last post by:
Trying to migrate from ASP classic to ColdFusion and was wondering how to handle this. A form has a text area that submits to a database and stores a memo that can later be viewed. How can I...
4
by: Steve Marson | last post by:
I am using a simple form in modx CMS and I need the textarea to retain the line breaks. I'd prefer a javascript solution if possible. This is because the textarea will be used to order food and...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.